Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

python 字符串拆分

作者:殇丶離別   发布日期:2025-09-21   浏览:21

# 示例代码: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版本

大家都在看

python时间格式

python读取文件路径

staticmethod在python中有

python开发windows应用程序

python中len是什么意思

python ord和chr

python中的yield

python自定义异常

python判断路径是否存在

python list.pop

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站