Skip to content
  • YouTube
  • FaceBook
  • Twitter
  • Instagram

Data Analytics Ireland

Data Analytics and Video Tutorials

  • Home
  • Contact
  • About Us
    • Latest
    • Write for us
    • Learn more information about our website
  • Useful Links
  • Glossary
  • All Categories
  • Faq
  • Livestream
  • Toggle search form
  • How To Compare CSV Files for Differences CSV
  • How to Pass Python Variables to Javascript Javascript
  • TypeError: ‘str’ object is not callable Python Functions
  • TypeError: expected str, bytes or os.PathLike object, not DataFrame Python
  • How to use parameters in Python Python
  • How To Validate Cell Values In Excel Python
  • How to Group By in a Select Statement SQL
  • how to remove unwanted characters from your data R Programming

TypeError: cannot unpack non-iterable int object

Posted on February 14, 2021April 12, 2021 By admin

Often when working on a data analytics project it requires you to split data out into its constituent parts.

There are a number of reasons for this, it can be confusing when you get errors as with the title of this post.

Before we explain this error and what it means, lets us first explain unpacking

Unpacking basically means splitting something up into a number of its parts that make it up.

To demonstrate if you take a,b,c = 123, and look to unpack it, it throws out the error, but why?

Well pure and simple, we have three values on the left “a,b,c”, looking for three values on the right.

a,b,c = 123
print(a)

Output:
 a,b,c = 123
TypeError: cannot unpack non-iterable int object

If you would like to fix this problem change the right hand side to have three values.

a,b,c = 1,2,3
print(a)
print(b)
print(c)
print(a,b,c)

Output:
1
2
3
1 2 3

Process finished with exit code 0

In essence, what is going on is that an evaluation checking that both sides have the same amount of values.

It is important to remember, the code above we used to show the error is an integer, which cannot be unpacked.

So if you take 123 for an example, which we used here it cannot be split into say 100 and 10 and 13.

In this case, even though when they are added up to 123, integers cannot be unpacked.

For this reason in the code for our solution, the difference is that the values used are tuples as follows:

a,b,c = 1,2,3
print(a)
print(b)
print(c)
print(a,b,c)
print(type((a,b,c)))

Or 
a,b,c = (1,2,3)
print(a)
print(b)
print(c)
print(a,b,c)
print(type((a,b,c)))

yield the same result:

1
2
3
1 2 3
<class 'tuple'>

Process finished with exit code 0

So in summary:

When unpacking there are a number of things to remember:

  • Integers on their own cannot be unpacked.
  • You need to make sure that if you have a number of variables, that you have the same number of integers if they the values.
    • This will make it a tuple and unpacking can then happen.

Python, type error Tags:Data Analytics, int, int object, integers, non-iterable, unpacking

Post navigation

Previous Post: What is a Primary Key and Foreign Key
Next Post: TypeError: ‘str’ object is not callable

Related Posts

  • How to Pass a Javascript Variable to Python using JSON Flask
  • how to create charts in Tkinter Python
  • How do I fix TypeError: unhashable type: ‘list’ Error? Articles
  • TypeError: the first argument must be callable Python
  • How to delete a key from a Python dictionary Python
  • What Is An Array In Python? array

Select your language!

  • हिंदी
  • Español
  • Português
  • Français
  • Italiano
  • Deutsch
  • How to delete a key from a Python dictionary Python
  • IndexError: index 2 is out of bounds for axis 0 with size 2 Index Error
  • Tableau Desktop versus Tableau Server data visualisation
  • TypeError: ‘list’ object is not an iterator Python
  • how to add sine and cosine in python code numpy
  • how do I declare a null value in python? exception handling
  • how to remove spaces from a string regular expressions
  • how to update records in SQL CRUD

Copyright © 2023 Data Analytics Ireland.

Powered by PressBook Premium theme

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT