BeginnerLesson 2 of 12
Variables & Data Types – Python
Numbers, text, Booleans and how Python handles types.
A variable is a name for a value. You do not have to specify a type – Python figures it out itself (dynamic typing).
name = "Ada" # str (text)
alter = 36 # int (integer)
groesse = 1.68 # float (decimal number)
aktiv = True # bool (Boolean)
nichts = None # NoneType (no value)
print(type(name), type(alter), type(groesse))With f-strings you build text from values. You convert types with int(), float(), str().
print(f"{name} is {alter} years old")
zahl = int("42") + 1
print(zahl) # 43
print(7 / 2, 7 // 2, 7 % 2, 2 ** 10) # 3.5 3 1 1024Warning
/ always returns a float (7 / 2 = 3.5). For integer division use //.