πVariables
Last updated
pythonCopy codex, y, z = 1, 2, 3pythonCopy codex = 5 # integer
y = 3.14 # float
z = "Hello" # string
a = [1, 2, 3] # list
b = (4, 5, 6) # tuple
c = {"name": "John", "age": 30} # dictionaryx = 5 # global variable
def my_function():
y = 3 # local variable
print(x) # global variable accessible within function
print(y) # local variable accessible within function
my_function()
print(x) # global variable accessible outside function
print(y) # error - local variable not accessible outside function