s2='we are chinese'分别提取"we"和"are"两个子串
时间: 2023-07-06 16:13:02 浏览: 60
判定一个串是否为另一个串的子串
可以使用字符串的 split() 方法实现:
```
s2 = 'we are chinese'
substrings = s2.split(' ')
print(substrings[0]) # 输出 we
print(substrings[1]) # 输出 are
```
或者使用字符串的切片操作:
```
s2 = 'we are chinese'
sub1 = s2[0:2] # 切片,提取前两个字符
sub2 = s2[3:6] # 切片,提取中间的三个字符
print(sub1) # 输出 we
print(sub2) # 输出 are
```
阅读全文