Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python assigning multiple variables to same list value?

Tags:

python

list

I'm writing a function to calculate calendar dates. While cutting down on lines, I've found that I am unable to assign multiple variables to the same range.

Jan, Mar, May, Jul, Aug, Oct, Dec = range(1,32)

Would there be an efficient way to assign these values and why does python give a ValueError?

like image 666
tijko Avatar asked Jun 01 '12 21:06

tijko


People also ask

Is it possible to assign multiple VAR to values in list?

We generally come through the task of getting certain index values and assigning variables out of them. The general approach we follow is to extract each list element by its index and then assign it to variables. This approach requires more line of code.

How do you add multiple variables to a list in Python?

You can use the sequence method list. extend to extend the list by multiple values from any kind of iterable, being it another list or any other thing that provides a sequence of values. So you can use list. append() to append a single value, and list.

How do you assign different values to multiple variables simultaneously?

Python assigns values from right to left. When assigning multiple variables in a single line, different variable names are provided to the left of the assignment operator separated by a comma.

Is Python allows you to assign a single value to several variables simultaneously?

Python allows you to assign a single value to several variables simultaneously. Here, two integer objects with values 1 and 2 are assigned to the variables a and b respectively, and one string object with the value "john" is assigned to the variable c.


1 Answers

Use

Jan = Mar = May = ... = range(1, 32)
like image 172
Guido van Rossum Avatar answered Oct 18 '22 20:10

Guido van Rossum