Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / Convert list to tuple in Python

Convert list to tuple in Python

August 20, 2021 by James Palmer

It should work fine. Don’t use tuple, list or other special names as a variable name. It’s probably what’s causing your problem.
>>> l = [4,5,6]
>>> tuple(l)
(4, 5, 6)

>>> tuple = ‘whoops’ # Don’t do this
>>> tuple(l)
TypeError: ‘tuple’ object is not callable

Expanding on eumiro’s comment, normally tuple(l) will convert a list l into a tuple:
In [1]: l = [4,5,6]

In [2]: tuple
Out[2]:

In [3]: tuple(l)
Out[3]: (4, 5, 6)

However, if you’ve redefined tuple to be a tuple rather than the type tuple:
In [4]: tuple = tuple(l)

In [5]: tuple
Out[5]: (4, 5, 6)

then you get a TypeError since the tuple itself is not callable:
In [6]: tuple(l)
TypeError: ‘tuple’ object is not callable

You can recover the original definition for tuple by quitting and restarting your interpreter, or (thanks to @glglgl):
In [6]: del tuple

In [7]: tuple
Out[7]:

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in