declare multiple variables in one line in python
January 11th, 2007 by Lawrence David
to declare several variables in one line, use multiple equals signs:
var1 = var2 = var3 = var4 = 0
be careful though using this form to declare dicts; due to python’s mutability rules, multiple dictionaries instantiated this way will all point to the same set of keys and values!
67df4075e33e…
67df4075e33eccaedd82…
Another way to do the same thing which allows for assigning different values to each variable is by using the tuples:
var1, var2, var3, var4 = 0, 0, 0, 0
Awesome, thanks!