0

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

Erin Hwang
  • 57
  • 1
  • 6

2 Answers2

3
total, x = 0, 1

it means :

total = 0 

and

x = 1 
Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53
0

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
Ari
  • 5,301
  • 8
  • 46
  • 120