Python: Variable

By Xah Lee. Date: .

Creating a variable

name = "Alice"
age = 20

Multiple assignment

a, b, c = 1, 2, 3
print(a,b,c)
# 1 2 3

# all set to 0
a = b = c = 0
print(a,b,c)
# 0 0 0

Allowed characters in variable names

Changing a variable value

x = 10
print(x)
# 10

# reassign
x = "ten"
print(x)
# ten

Checking the type

x = 3
print(type(x))
# <class 'int'>

Python, variable and operators