I’m trying to convert a list to a tuple.
Most solutions on Google offer the following code:
JavaScript
x
3
1
l = [4,5,6]
2
tuple(l)
3
However, the code results in an error message when I run it:
TypeError: ‘tuple’ object is not callable
How can I fix this problem?
Advertisement
Answer
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.
JavaScript
1
8
1
>>> l = [4,5,6]
2
>>> tuple(l)
3
(4, 5, 6)
4
5
>>> tuple = 'whoops' # Don't do this
6
>>> tuple(l)
7
TypeError: 'tuple' object is not callable
8