Back Navigation Next Navigation Conceptual Review (page 15 of 55)

Variables do not need to be declared with any data type.

x = 7 # This statement will create an int variable named x
x = True # We can reuse the variable x with a different data type

We can even change the object type after variables have been set.

x = 7 # This statement will create an int variable named x
x = str(x) # This statement will convert the int x variable to a str.

Casting or changing the data type of a variable is often needed.

x = str(1) # This statement casts the int 1 to a str.
x = float(1) # This statement casts the int 1 to a float

Casting