I'm trying to fundamentally understand while loops but don't understand assigning multiple variables on a single line of code.
total, x = 0, 1
What does the 1 mean? Where does the 1 belong? Plz help
I'm trying to fundamentally understand while loops but don't understand assigning multiple variables on a single line of code.
total, x = 0, 1
What does the 1 mean? Where does the 1 belong? Plz help
You are basically assigning two variables simultaneously.
cat, dog = 'meow', 'woof'
is the same as:
cat = 'meow'
dog = 'woof'
You can use this method when you have a function that needs to return multiple variables.
def my_func(text):
return text, text.upper()
(original, edited) = my_func('hello')
print(original)
print(edited)
>>> hello
>>> HELLO