# 示例代码:Python 字符串拆分
# 使用 split() 方法将字符串按指定分隔符拆分为列表
text = "apple,banana,orange"
result = text.split(",") # 按逗号拆分
print(result) # 输出: ['apple', 'banana', 'orange']
# 如果不指定分隔符,split() 默认按空格拆分
sentence = "Hello world this is Python"
result = sentence.split() # 按空格拆分
print(result) # 输出: ['Hello', 'world', 'this', 'is', 'Python']
# 使用 maxsplit 参数限制拆分次数
text = "one,two,three,four"
result = text.split(",", 2) # 最多拆分两次
print(result) # 输出: ['one', 'two', 'three,four']
上一篇:python multiprocessing pool
下一篇:查python版本
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站