To make tuple but it's hard
我只想让tuple使用list所以,
1 2 | list1 = [1,2] a = tuple(list1) |
我使用了这个代码,但它是错误的。
TypeError: 'tuple' object is not callable
为什么不做tuple?
正如您在这个问题中看到的,在python中将list转换为tuple
当然,你称之为
例如:
1 2 | list = [1,3] tuple = (2,3) |
只有这种代码的和平,才有效,但是如果你试着这么做的话
1 2 3 | list = [1,3] tuple = (2,3) a = tuple(list) |
你会得到错误
TypeError: 'tuple' object is not callable
其他可能的情况:
1 2 3 4 | list = [1,2,3,4] print(list) $[1,2,3,4] |
但是:
1 2 3 4 | list = [1,2,3,4] print(list) other_list = list((1,2,3,4)) print(other_list) |
TypeError: 'list' object is not callable
因为你重新定义了
解决方案很简单,请重命名变量,例如:
1 2 3 4 5 6 | lst = [1,3] tpl = (4,5) a = tuple(lst) print(a) $(1,3) |