如何从列表中删除单引号?

时间:2018-12-13 11:33:10

标签: python

##i have the data to append to a Arraylist
Global = 'none' ##Basically i need to append this header
header = ['/', Global.strip("'"), 0] ##header
['/', 'none', 0]     ##Actual Output
['/', none, 0]      ##I need the Expected Output without single quotes

3 个答案:

答案 0 :(得分:1)

字符串包含哪些字符表示的方式之间存在区别(例如,使用python repl时。请参见以下示例:

>>> x = "hello"
>>> x
'hello'
>>> print(x)
hello
>>>

上面的字符串x不包含任何引号,只是以这种方式显示。这用于例如使数字和包含数字的字符串看起来不同:

>>> a = 1
>>> b = "1"
>>> a
1
>>> b
'1'

这有帮助吗?如果不是,请说明您是在谈论数据表示形式还是实际数据本身。

答案 1 :(得分:1)

尝试这个

Global = 'none' 
header = ['/', Global, 0] 
print ('[%s]' % ', '.join(map(str, header)))

答案 2 :(得分:0)

这完全符合您的要求:-

    Global = 'none' 
    header = ['/', Global, 0]
    print ('[%s]' % ', '.join(map(str, header)).replace( "/","'/'"))

输出:-['/',none,0] (您可以在此处https://onlinegdb.com/rJ5COTye4中查看)