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

split函数的用法python

作者:恋你如初   发布日期:2025-10-08   浏览:29

# 示例代码:split函数的用法

# split() 方法用于将字符串按照指定的分隔符进行分割,并返回一个列表。
# 语法:str.split(separator, maxsplit)

text = "Hello, this is a test string."

# 使用逗号作为分隔符
result1 = text.split(",")  # ['Hello', ' this is a test string.']
print("使用逗号作为分隔符:", result1)

# 使用空格作为分隔符
result2 = text.split(" ")  # ['Hello,', 'this', 'is', 'a', 'test', 'string.']
print("使用空格作为分隔符:", result2)

# 指定最大分割次数
result3 = text.split(" ", 3)  # ['Hello,', 'this', 'is', 'a test string.']
print("指定最大分割次数:", result3)

# 不指定分隔符,默认为空格,连续的空格会被视为一个分隔符
result4 = text.split()  # ['Hello,', 'this', 'is', 'a', 'test', 'string.']
print("不指定分隔符:", result4)

上一篇:python re.split

下一篇:python的print()函数

大家都在看

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 中文站