0

I just want to make tuple to using list so,

list1 = [1,2]
a = tuple(list1)

I used this code but it's error..

TypeError: 'tuple' object is not callable

Why don't make tuple?

developer_hatch
  • 15,898
  • 3
  • 42
  • 75
wooojuns
  • 11
  • 2
  • Works for me. Try again as edited. – pylang Jun 15 '17 at 04:21
  • 4
    Somewhere in your code, you've defined a variable of _type_ `tuple` _named_ `tuple`. This name is then shadowing the `tuple` built-in when you try to use it again. __Don't shadow built-in function names__. – miradulo Jun 15 '17 at 04:21

1 Answers1

1

As you can see in this question Convert list to tuple in Python

You by sure called a variable like list or tuple, those words are built in types and can be redefined, which is a great source of errors

by example:

list = [1,3]
tuple = (2,3)

only this peace of code, works fine, but if you try to do

list = [1,3]
tuple = (2,3)
a = tuple(list)

you will get the error

TypeError: 'tuple' object is not callable

other posible scenario:

list = [1,2,3,4]
print(list)

$[1,2,3,4]

but:

list = [1,2,3,4]
print(list)
other_list = list((1,2,3,4))
print(other_list)

TypeError: 'list' object is not callable

because you redefined list and now is an object, the object [1,2,3,4]

the solution is simple, rename your variables, example:

lst = [1,3]
tpl = (4,5)
a = tuple(lst)
print(a)

$(1,3)
developer_hatch
  • 15,898
  • 3
  • 42
  • 75