Assignment statement in Python

Lesson#8

Values are assigned to variables using assignment operator ( = ).

Typical examples of assignment statement are:

x = 100
y = "Car"

Assignment statement is much powerful in Python than other programming languages.

One value can be assigned to multiple variables in Python as:

x = y = z = 100

This statement will assign the value 100 to three variables x, y and z.

We can also assign different values to multiple variables in single assignment statement:

x , y , z = "Cat" , "Dog" , "Cow"

We can also unpack values from lists or tuples [will be explained later] into variables:

cities = ["London", "Tokyo", "New York"]
x , y , z = cities

This assignment will assign “London” to x, “Tokyo” to y and “New York” to z.

--

--