# 示例代码:split() 函数用法
# split() 函数用于将字符串按照指定的分隔符分割成列表,默认分隔符是空格。
text = "Hello, this is a test string"
result = text.split()
print(result) # 输出: ['Hello,', 'this', 'is', 'a', 'test', 'string']
# 使用逗号作为分隔符
text = "apple,banana,orange"
result = text.split(',')
print(result) # 输出: ['apple', 'banana', 'orange']
# 限制分割次数
text = "one,two,three,four"
result = text.split(',', 2)
print(result) # 输出: ['one', 'two', 'three,four']
split()
函数可以不带参数调用,此时它会按照任意空白字符(如空格、制表符、换行符等)进行分割。,
或者其他符号。上一篇:python mvc
下一篇:python print %
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站