Variables and types
Names, numbers, strings, booleans, None, and converting between types.
Runs in Zerethon IDE · Python 3.12
Official Python documentation ↗
A variable is created by assigning to it; it has no declared type. The value has the type, and type() shows it.
main.py
count = 3 # int
price = 9.5 # float
name = "Ada" # str
ready = True # bool
nothing = None # NoneType
print(type(count).__name__, type(price).__name__, type(name).__name__)
print(int("42") + 1, float("2.5") * 2, str(7) + "7")
print(7 / 2, 7 // 2, 7 % 2, 2 ** 10)
Output
int float str 43 5.0 77 3.5 3 1 1024
/always gives a float;//is floor division;**is power.int("4.5")fails — convert withfloat()first, orint(float("4.5")).- Compare with
Noneusingis None, not== None.
Tip: Type hints such as count: int = 3 document intent but are not checked when the program runs.