Assign Multiple Values to Variable in Python

Assign Multiple Values to Variables in Python in one line:

x, y, z = "Orange", "Kiwi", "Apple"

One thing to care about when assigning multiple variables in one line is to match the number of variables and the values or you’ll get an error.



Get values from List to variables in Python:

same here, the number of variables must match the values in the list.

Numbers = ["one", "two", "Three"]
x, y, z = Numbers
print(x)
print(y)
print(z)

Bilel-A

Enthusiastic Network Engineer specializing in Cisco ACI, passionate about solving challenges. A lifelong learner who loves gaining and sharing knowledge. Profile: https://www.linkedin.com/in/bilel-ameur-71116b2b5
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x