split()方法有以下參數(shù):
示例用法:
str = "Hello World"
result = str.split() # 使用默認(rèn)的空格分隔符進(jìn)行分割
print(result) # 輸出:['Hello', 'World']
str = "apple,orange,banana"
result = str.split(",") # 使用逗號(hào)作為分隔符進(jìn)行分割
print(result) # 輸出:['apple', 'orange', 'banana']
str = "apple,orange,banana"
result = str.split(",", 1) # 使用逗號(hào)作為分隔符進(jìn)行分割,最多分割1次
print(result) # 輸出:['apple', 'orange,banana']