Python 将字符串转换为列表
我有这样一个字符串:Python 将字符串转换为列表,python,list,Python,List,我有这样一个字符串: 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 struct
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",.....]
我想分成以下几部分:
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,请帮助我您可以使用函数
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 ',
'']
可以按字符拆分字符串:
yourString = "Hello * my name * is * Alex"
yourStringSplitted = yourString.split('*')