Python variable scope 🔬

preview_player
Показать описание
Python variable scope tutorial example explained

#python #variable #scope

# ========================================================
# scope = The region that a variable is recognized
# A variable is only available from inside the region it is created.
# A global and locally scoped versions of a variable can be created

name = "Bro" # global scope (available inside & outside functions)

def display_name():
name = "Code" # local scope (available only inside this function)
print(name)

display_name()
print(name)
# ========================================================

Bro Code merch store 👟 :
===========================================================
===========================================================
Рекомендации по теме
Комментарии
Автор

# scope = The region that a variable is recognized
# A variable is only available from inside the region it is created.
# A global and locally scoped version of a variable can be created

name = "Bro" # global scope (available inside & outside functions)

def display_name():
name = "Code" # local scope (available only inside this function)
print(name)


display_name()
print(name)

BroCodez
Автор

Thank you for making this so easy to understand!!! Excellent info!

garymaya
Автор

well explained! thank you! you are much appreciated <3

NadyaNinis-py
Автор

Bro!
There´s any other function where variables can be allocated as Local?
I mean, now i know that when I DEF a function, I cant use outside the variables inside that function. There´s any other space like DEF that makes a variable a local variable?

Thanks bro, hugs from Colombia

nikoprieto
Автор

im a bro ye im a bro
appreciate your work <3

happycoder