这是我的代码:
list = []
text = input("Please give your text:")
text = str(text)
list.append(text)
list = str(list)
我想提供输入,例如:abcd。然后,我希望它将其分割为[“ a”,“ b”,“ c”,“ d”]
答案 0 :(得分:3)
另一个选择:
text = input("Please give your text:")
l = list(text)
print (l)
答案 1 :(得分:2)
首先,避免将变量命名为For Each pvt In shSource.PivotTables
On Error Resume Next
x = pvt.PivotCache.MemoryUsed
If Err.Description = "The PivotTable report was saved without the underlying data. Use the Refresh Data command to update the report." Then
pvt.ChangePivotCache ThisWorkbook.PivotCaches.Create (SourceType:=xlDatabase, SourceData:=rawDataRng)
pvt.SaveData = False
pvt.RefreshTable
End If
On Error GoTo 0
Next pvt
。然后,只需说出list
,即可将str
拆分为列表。
list(text)
输出
lst = []
text = input("Please give your text:")
lst.extend(list(text))
print (lst)
答案 2 :(得分:0)
Access the characters by Index。通过遍历字符串,可以分别提取每个字符。变量'1'
等于索引i
到0
的长度,您可以使用text
通过索引访问字符元素。请参见下面的示例:
text[i]
另一种方法是traverse the Strings as an iterable:
user_input_as_chars = []
text = input("Please give your text:")
for i in range(0, len(text)):
user_input_as_chars.append(text[i])
user_input_as_chars = str(list)
答案 3 :(得分:0)
text = input("Please give your text:")
list.extend(list(text))
print (list)