s='hello world python' s1='hello|world|python' '''字符串的劈分,输出结果都为为列表''' lst=s.split() #split中文翻译为分开 print('字符串的劈分,默认分开符号为空格,',lst) lst2=s1.split(sep='|',maxsplit=1) #sep 理解为分开 print('字符串的劈分,确定分开符号为|,分劈次数从左到右为1次,',lst2) lst3=s1.rsplit(sep='|',maxsplit=1) print('字符串的劈分,确定分开符号为|,分劈次数从右到左为1次,',lst3)
E:\PycharmProjects\pythonProject\venv\Scripts\python.exe E:/PycharmProjects/pythonProject/demon1/demo17.py 字符串的劈分,默认分开符号为空格, ['hello', 'world', 'python'] 字符串的劈分,确定分开符号为|,分劈次数从左到右为1次, ['hello', 'world|python'] 字符串的劈分,确定分开符号为|,分劈次数从右到左为1次, ['hello|world', 'python'] 进程已结束,退出代码0