Python - Variables

python logo pixel art

Variables store the data.


Variable Assignment

name = value
name1, name2, ... = value1, value2, ...
x = 10
y = '54'
z = x + int(y)

The variable name cannot be a reserved keyword such as if, def, import.


Variable Type

In Python, variables are dynamically typed, allowing you to assign them values of different types during runtime.

x = 10 # <- int
x = 'Hello, There!' # <- string
x = (1,2,3) # <- tuple

Checking Variable Type

You can use the type(x) function to check the type of a variable.

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

x = 'Hello, There!'
print(type(x)) # <class 'str'>

x = (1,2,3)
print(type(x)) # <class 'tuple'>