小册名称:Python合辑4-130个字符串操作示例
在Python中按字符串中字符的位置拆分字符串
str = 'canadajapan'splitat = 6l, r = str[:splitat], str[splitat:]print(l)print(r)
str = 'canadajapan'
splitat = 6
l, r = str[:splitat], str[splitat:]
print(l)
print(r)
Output:
canadajapan
canada
japan