Skip to content

← Back to Python Course Foundations

Python Variables

Learning Objectives

  • Apply valid variable naming rules.
  • Use dynamic typing and multiple assignment.
  • Distinguish local and global scope.

Example

x, y = 10, 20
name = "Asha"

count = 0

def increment():
    global count
    count += 1

increment()
print(x, y, name, count)

Dry Run

  • x=10, y=20, name=Asha
  • increment() updates global count to 1

Common Mistakes

  • Using keywords as variable names.
  • Expecting local function variable to update global value without global.

Practice

  1. Demonstrate type change in same variable.
  2. Create function with local and global variable comparison.