Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从列表中删除单引号?_Python - Fatal编程技术网

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

Python 如何从列表中删除单引号?,python,Python,字符串包含的字符和它的表示方式(例如,在使用python repl时)之间存在差异。请参见此示例: ##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]

字符串包含的字符和它的表示方式(例如,在使用python repl时)之间存在差异。请参见此示例:

##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
上面的字符串x不包含任何引号,它只是这样显示的。这用于使数字和包含数字的字符串看起来不同:

>>> x = "hello"
>>> x
'hello'
>>> print(x)
hello
>>>
这有用吗?如果不是,请澄清您所说的是数据表示还是实际数据本身。

试试这个

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

这正是您想要的:-

Global = 'none' 
header = ['/', Global, 0] 
print ('[%s]' % ', '.join(map(str, header)))
输出:-['/',无,0]
您可以在这里查看

对不起,您希望这里有什么空值?字符串或None作为None python对象您的问题不清楚,请将itA字符串重写为None,我需要删除None的单引号如果您打印sting,则不会在其周围加引号。引号直观地指示值是字符串。打印数组项或写入文件时,引号不存在。我不想打印值,我希望存储变量并使用它。比如x=hello。你用这个值做什么?您正在编写的程序的总体任务是什么?我为UI puprose编写了一个程序,其中我将数据传递到javascript的数据表,如果我传递头,它将带有单引号,因此我不需要单引号var data=google.visualization.arrayToDataTable[['Location','Parent','size'],['/','none',0],['warehouse-hive-events-schema','/',17754];您是否在使用python程序编写javascript代码?sry,而不是javascript,正在构建一个将值呈现到html模板的flask应用程序。var data=google.visualization.arrayToDataTable['Location','Parent','size'],['/','none',0','warehouse-hive-events-schema','/',17754];a='[%s]“%”,“.joinmapstr,header.replace/,“/”,>>>a[“/”,none,0],我如何删除双引号和storea.replace“”,可能的话。我需要靠近我的机器才能确定。我明天回来时会试试
    Global = 'none' 
    header = ['/', Global, 0]
    print ('[%s]' % ', '.join(map(str, header)).replace( "/","'/'"))