新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:splitlines在python中返回列表
說明

1、splitlines()方法用于按照換行符(\r、\r\n、\n) 分割。
2、返回一個(gè)是否包含換行符的列表,如果參數(shù)keepends為False,則不包含換行符。
如果為True,則包含換行符。
返回值
返回是否包含換行符的列表。
實(shí)例
str1 = 'Amo\r\nPaul\r\nJerry' list1 = str1.splitlines() # 不帶換行符的列表 print(list1) print(list1[0], list1[1], list1[2]) list2 = str1.splitlines(True) # 帶換行符的列表 print(list2) print(list2[0], list2[1], list2[2], sep='') # 使用sep去掉空格
以上就是splitlines在python中返回列表的方法,在列表的操作中有時(shí)候會(huì)遇到,大家可以對(duì)基本用法進(jìn)行了解。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)Python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
本文名稱:創(chuàng)新互聯(lián)Python教程:splitlines在python中返回列表
當(dāng)前URL:http://www.dlmjj.cn/article/cdephgs.html


咨詢
建站咨詢
