我有一个这样的字符串:
st = "The most basic data structure in Python is the sequence * Each element of a sequence is assigned a number * its position or index * The first index is zero * the second index is one * and so forth *"
我希望像这样分成列表:
ls =["The most basic data structure in Python is the sequence","Each element of a sequence is assigned a number","its position or index",.....]
我刚刚开始python,请帮帮我
答案 0 :(得分:2)
您可以按字符分割字符串:
yourString = "Hello * my name * is * Alex"
yourStringSplitted = yourString.split('*')
答案 1 :(得分:1)
您可以使用函数str.split
将字符串拆分为特定字符的数组:
>>> str.split(st,"*")
['The most basic data structure in Python is the sequence ',
' Each element of a sequence is assigned a number ',
' its position or index ',
' The first index is zero ',
' the second index is one ',
' and so forth ',
'']