我有一个以这种格式表示的字符串:
[[u'This is a string']], what does this mean??
我怎样才能把它变成:
[u'This is a string']
或者
['This is a string']
>>> data = [[u'This is a string']]
>>> data[0][0]
u'This is a string'
前缀u'...'
表示 unicode
>>> print data[0][0]
This is a string
它工作得很好,就这样吧。但是出于教育目的,这是您将其转换回普通 Python 2.7 的方式str
>>> str(data[0][0])
'This is a string'
好吧,您在列表中有一个列表,而内部列表包含一个字符串。所以:
x = [[u'This is a string']]
print x[0] # first element of the outer list will be the inner list
print x[0][0] # first element of the inner list is the string
它在列表中,在列表中。
要访问它:
[[u'This is a string']][0]
如果你想要字符串:
[[u'This is a string']][0][0]