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
  • What are bitwise operators in Julia? julia
  • How to Create Multiple XML Files From Excel With Python Python
  • supervised machine learning vs unsupervised machine learning? machine learning
  • How To Check For Unwanted Characters Using Loops With Python Python Data Cleansing
  • How do I fix TypeError: unhashable type: ‘list’ Error? Articles
  • how to select all records with SQL SQL
  • how to reverse a string in python strings
  • YouTube channel lists – Python Lists Python Lists

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

  • python constructor self and __init__explained Python
  • TypeError: the first argument must be callable Python
  • TypeError: ‘str’ object is not callable Python Functions
  • Tkinter GUI tutorial python – how to clean excel data Python
  • TypeError: expected str, bytes or os.PathLike object, not DataFrame Python
  • How to use zip() function in Python Python

Select your language!

  • English
  • हिंदी
  • Español
  • Français
  • Italiano
  • Deutsch
  • How to connect to your data in Tableau data visualisation
  • raise an exception in python class
  • How To Add Values to a Python Dictionary Python
  • R Tutorial: How to pass data between functions R Programming
  • R – How to open a file R Programming
  • hide a column from a data frame Python Dataframe
  • TypeError: List Indices Must Be Integers Or Slices, Not Tuple exceptions
  • how to insert data into a table in SQL SQL

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