emie
emie

Reputation: 289

Python - cannot unpack non-iterable int object when declaring variable

I get the following error "cannot unpack non-iterable int object" when attempting to run the following line of code.

numOf95Rows, numOf85Rows, numOf85Rows, numOf75Rows, numOfLess75Rows = 0

But when I specifically declare each variable, I do not get the error. Why is that?

numOf95Rows = 0
numOf85Rows = 0 
numOf85Rows = 0
numOf75Rows = 0 
numOfLess75Rows = 0

Upvotes: 1

Views: 4330

Answers (2)

Vishal Upadhyay
Vishal Upadhyay

Reputation: 811

If you want to assign same value to multiple variables than instead of using , use =

Code

numOf95Rows = numOf85Rows = numOf85Rows = numOf75Rows = numOfLess75Rows = 0
print(numOf95Rows)

Output

0

Refer this doc for more information

Upvotes: 0

Achy97
Achy97

Reputation: 1024

Your error will be resolved by this

numOf95Rows, numOf85Rows, numOf85Rows, numOf75Rows, numOfLess75Rows = 0,0,0,0,0

In python when you are using any this kind of multi-assignment then the right hand side must be an iterable or same number of values as variabbles delimited by comma.

You are getting this error because there is only 1 variable which is integer and non-iterable, thats why it cannot un-pack the value like an iterable to assign the values.

Hope this helps

Upvotes: 1

Related Questions