TypeError:使用列表和字符串转换无法调用“ str”对象

时间:2019-02-21 16:40:30

标签: python string list

使用到目前为止我尝试过的代码,出现如下错误:

   L=[1,2,3,4]
   s1 = ":".join(str(x)for x in L)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-128-9a830429dd90> in <module>
      1 L=[1,2,3,4]
----> 2 s1 = ":".join(str(x)for x in L)
      3 
      4 

<ipython-input-128-9a830429dd90> in <genexpr>(.0)
      1 L=[1,2,3,4]
----> 2 s1 = ":".join(str(x)for x in L)
      3 
      4 

TypeError: 'str' object is not callable

即使尝试以下代码:

for x in L :
    print(str(x))
s1 = ":".join(str(x)for x in L)

I get below error
----> 3     print(str(x))
      4 s1 = ":".join(str(x)for x in L)
      5 

TypeError: 'str' object is not callable

我正在Jupyter笔记本Python版本:3.7.1中运行此代码

0 个答案:

没有答案