Introduction
Variable assignment lets you store information to use later in your program. It helps keep track of values like numbers or words.
Jump into concepts and practice - no test required
Variable assignment lets you store information to use later in your program. It helps keep track of values like numbers or words.
variable_name = value
The = sign means 'store this value in the variable'.
Variable names should start with a letter or underscore and have no spaces.
name.name = "Alice"age.age = 30temperature.temperature = 23.5is_raining.is_raining = FalseThis program saves a name and age, then prints them out.
name = "Bob" age = 25 print(f"Name: {name}") print(f"Age: {age}")
You can change a variable's value anytime by assigning a new value.
Variable names are case sensitive: Age and age are different.
Use meaningful names to make your code easier to understand.
Variable assignment stores values to use later.
Use = to assign values to variables.
Choose clear names and remember variables can change.
age = 25= sign in Python assigns the value on the right to the variable on the left.age = 25age.count in Python?= is used to assign values to variables.== which is a comparison, not assignment. 10 = count tries to assign to a value, which is invalid. count := 10 uses walrus operator := which is valid in Python 3.8+, but not standard for simple assignment. count = 10 correctly assigns 10 to count.name = "Alice" age = 30 name = "Bob" print(name, age)
name is set to "Alice" and age to 30. Then name is reassigned to "Bob".name and age. Since name was changed to "Bob", and age remains 30, the output is "Bob 30".5number = 10 print(5number)
5number starts with a digit, which is invalid syntax and causes an error.a and b in Python. Which of the following is the correct way to do it?a gets b's value and b gets a's value.b to a, then a to b, losing original a. temp = a
b = temp
a = b incorrectly assigns b before a. a = a + b
b = a - b
a = a - b uses arithmetic swap which works but is less clear and can cause errors with non-numbers. a, b = b, a uses Python's tuple unpacking to swap values correctly and clearly.