Python multiple assignment

Python Multiple Assignment #

Assign multiple variables.

a, b = "Hello", "World"

print(a)
# "Hello"

print(b)

# "World"

If there’s just one variable but multiple values, it becomes a tuple:


a = 1, 2

print(type(a))
# <class 'tuple'>

If there’s a mismatched number of variables and values, there’s going to be a ValueError.