Guidelines

Important Points When Assigning Values to Variables

In programming, assignment refers to the process of storing a specific value in a declared variable.

For example, x = 5 means that the value 5 is stored in the variable x.

In the previous lesson, initialization refers to the process of assigning values to a declared variable.


Important Notice

In programming, the = symbol does not mean "equals" as in mathematics, but rather means assign the value on the right to the variable on the left.

Example of Variable Assignment
number = 10 message = "Hello, Python!"

In the code above, number = 10 means assigning the number 10 to the variable number.

Similarly, message = "Hello, Python!" assigns the string "Hello, Python!" to the variable message.

When using an equal sign to mean "equals," use two equal signs as in ==.

Using Equal Sign to Mean 'Equals'
if number == 10: print("number is 10.")

Variable Reassignment

In Python, you can assign a new value to an already assigned variable.

In this case, the previous value is replaced with the reassigned value.

Example of Variable Reassignment
number = 10 # Assign the value 10 to the variable number number = 15 # Reassign the new value 15 to number, which was initially 10

Multiple Assignment

In Python, you can assign values to multiple variables simultaneously in one line.

Example of Multiple Assignment
x, y, z = 5, 10, 15 print(x) # 5 print(y) # 10 print(z) # 15

Coding Practice

Try reassigning the value of the variable student_name.

Mission
0 / 1

What does the equals sign (=) mean when assigning values to a variable?

In programming, the '=' symbol does not mean 'equals' as in math, but indicates assigning the value on the right to the .
compare
add
move to the left
assign to the variable on the left

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result