Variables and Data Types
Every prompt, temperature setting, and model response in Python is stored under a name and shaped by its data type. Understanding how Python names values and checks types is the first step in building reliable AI systems.
Names point to values in memory.
When you write Python code to interact with an AI model, you frequently work with configuration parameters: token limits, temperatures, and system prompts. To keep track of these values, Python uses variables.
A variable in Python is not a permanent box that can only hold one kind of data. Instead, think of a variable as a sticky note or name tag attached to an object in your computer's memory. You assign a name using the single equals sign (=):
= operator evaluates the expression on its right-hand side first, creates that value in memory, and then attaches the name on the left to it.This is fundamentally different from mathematical equality. In algebra, the statement count = count + 1 is an impossible equation. In Python, it is a routine operation:
count = 3
count = count + 1 # count now points to 4
Reassigning a variable does not overwrite the number 3 in memory; it simply moves the name tag count to point to the new number 4.

Four primitive types power AI code.
Every object in Python has a type. The type tells Python what the data represents, how much memory it occupies, and what operations (such as addition or concatenation) are allowed. Four primitive types appear in nearly every AI script:
prompt = "Summarize this"Sequences of characters wrapped in quotes. Used for user prompts, system instructions, and raw model completions.
max_tokens = 500Whole numbers without decimal points. Used for discrete counts, token budgets, retry limits, and batch sizes.
temperature = 0.7Numbers with decimal points. Used for model sampling parameters, probability scores, loss metrics, and embeddings.
stream = TrueLogical truth values: either True or False (capitalized, without quotes). Used for feature flags, safety checks, and API switches.
You can inspect the type of any variable at runtime using Python's built-in type() function:
type(500) # returns <class 'int'>
type(0.7) # returns <class 'float'>
type("gemini") # returns <class 'str'>
type(True) # returns <class 'bool'>
Inspect variables and types in the sandbox.
Use the interactive sandbox below to explore how Python assigns and inspects AI configuration parameters. Select different parameters, test what happens when a number is accidentally wrapped in quotes, and test operations like addition and API validation.
AI Parameter & Type Sandbox
Live Inspectionmax_tokens = 500
2. Mental Model: Name points to Object in Memory
Runtime Inspection
3. Test an Operation
max_tokens + 100 # Result: 600Numeric addition: Python adds the integers together, producing 600.
Quotes create text, not numbers.
One of the most frequent bugs in AI applications involves confusing a number with a string of digits:
500is an int. Python treats it as a mathematical quantity and can add, subtract, and compare it."500"is a str. Python treats it as a sequence of text characters (the character '5' followed by two zeros).
Python behaves differently depending on the types involved:
500 + 100 # 600
"500" + "100" # "500100"
"500" + 100 # TypeError: can only concatenate str (not "int") to str
Unlike some programming languages (like JavaScript) that quietly convert strings to numbers on the fly, Python is strongly typed. It refuses to guess your intention and raises a TypeError if you try to combine incompatible types.
True is a boolean truth value, while "True" and "False" are text strings. Because Python treats any non-empty string as "truthy", running bool("False") evaluates to True! Always use the unquoted keywords True and False for boolean flags.Converting types safely for model inputs.
When you read configuration values from environment variables (such as os.getenv("MAX_TOKENS")) or receive user inputs from web forms, the data almost always arrives as a str.
Before passing these values to an AI SDK or model API that expects numeric parameters, you must explicitly convert (or "cast") them:
import os
raw_limit = os.getenv("MAX_TOKENS", "1000") # type is str
max_tokens = int(raw_limit) # type is int (1000)
temperature = float("0.7") # type is float (0.7)
Two different errors can occur during configuration loading:
- Missing variables (
TypeError): Ifos.getenv("MAX_TOKENS")is unset without a default, it returnsNone. PassingNonetoint()raises aTypeError. Setting a fallback default string prevents this. - Invalid text (
ValueError): If the string cannot be parsed as a number (such asint("unlimited")), Python raises aValueError.
int("unlimited") # ValueError: invalid literal for int() with base 10
In production AI pipelines, converting and validating types early prevents malformed requests from reaching your model provider.
Check your understanding.
Take this with you.
Variables are name tags that point to typed objects in memory, not fixed storage boxes. Python's four core primitive types (str, int, float, and bool) govern what operations are valid. Quotes turn numbers into text, and Python requires explicit conversion (such as int() or float()) when passing string inputs to numeric AI APIs.