python list转换str

在django中的console中

li
Out[33]: 
['192.168.68.138',
 '192.168.23.26',
 '192.168.21.28',
 '192.168.23.21',
 '192.168.23.61']
str(li)
Traceback (most recent call last):
  File "C:\Users\liangshuo\AppData\Local\Programs\Python\Python36\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-34-a99d6e5f05a9>", line 1, in <module>
    str(li)
TypeError: 'str' object is not callable

在python解释器中

PS C:\Windows\system32> python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> li = ['192.168.68.138', '192.168.23.26', '192.168.21.28', '192.168.23.21', '192.168.23.61']
>>>
>>> str(li)
"['192.168.68.138', '192.168.23.26', '192.168.21.28', '192.168.23.21', '192.168.23.61']"
>>>

猜你喜欢

转载自www.cnblogs.com/venicid/p/12097322.html