Local Variable
noun
say it: “LOH-kul VAIR-ee-uh-bul” /ˈloʊkəl ˈvɛəriəbəl/
A variable created inside a function; it exists only while that function runs, and the rest of the program can't see it.
What is a local variable?
A local variable is created inside a function. It exists only while that function runs, and the rest of the program can't see it.
def add_tax(price):
tax = price * 0.07 # local to add_tax
return price + tax
print(add_tax(100)) # 107.0
In a sentence
- “Printing a local variable outside its function gives a NameError.”
- “tax is a local variable inside add_tax.”
Level: Apprentice · More Python terms at this level
Updated