Python Variables - Assign Multiple Values
Many Values to Multiple Variables
Python allows you to assign values to multiple variables in one line:
ExampleGet your own Python Server
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
Try it Yourself »
Note: Make sure the number of variables matches the number of values, or else you will get an error.
One Value to Multiple Variables
And you can assign the same value to multiple variables in one line:
Unpack a Collection
If you have a collection of values in a list, tuple etc. Python allows you to extract the values into variables. This is called unpacking.
Example
Unpack a list:
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)
Try it Yourself »
Learn more about unpacking in our Unpack Tuples Chapter.
Exercise?What is this?
Test your skills by answering a few questions about the topics of this page
What is a correct syntax to add the value 'Hello World', to 3 variables in one statement?
Video: Python Variable Names
![Python Tutorial on YouTube](images/yt_logo_rgb_dark.png)
![Python Tutorial on YouTube](images/img_python_variables_multiple_values.png)