當前位置:首頁 » 編程語言 » python分割

python分割

發布時間: 2022-01-23 08:45:28

python 怎麼分割 

可以使用split()
用法是這樣的,你只要在括弧裡面打上你需要以什麼分割就可以了,比如你要以#分割,那就split("#")。例如a = "a#a#a", b = a.split("#") >>> print b 就輸出[a,a,a]

② python split處理分割

>>>a='46003,2013/11/0215:21:56,/mmsns/'
>>>id,tm,addr=a.split(',',2)
>>>id,tm,addr
('46003','2013/11/0215:21:56','/mmsns/')
>>>a='46003,2013/11/0215:21:56,/mmsns/M6CLCDD0GAysp3,sbCxsCeKXxhDI4xHkt0sf8ick'
>>>id,tm,addr=a.split(',',2)
>>>id,tm,addr
('46003','2013/11/0215:21:56','/mmsns/M6CLCDD0GAysp3,sbCxsCeKXxhDI4xHkt0sf8ick')
>>>

③ python 字元串分割截取

>>>
10.1.1.100,10.2.100.125,189.10.2.40,189.0.100.50
10.1.1.1,10.2.100.1,189.10.2.1,189.0.100.1str='10.1.1.100,10.2.100.125,189.10.2.40,189.0.100.50'
print(str)
str=str.split(',')
str1=[]
forelementinstr:
list=element.split('.')
list[len(list)-1]='1'
list='.'.join(list)
str1.append(list)
str1=','.join(str1)
print(str1)

④ python按大小分割字元串

沒用理解按大小分割的意思,大概是按指定長度分割吧?
比較直接的方法:
# 比如7個字元分割
c =7
s ='asdfaddsfgsdfgdsfgsdfg'
print [s[i:i+c] for i in xrange(0,len(s),c)]

⑤ python如何拆分字元串

⑥ python字元串分割

格式太亂了,給你個參考吧
import re
s = 'type <unsigned int>\nport_num:4\nport:<in_port><sc_out<sc_uint<4>>>'
a = s.split('\n')
ok = []
for i in a:
if re.match('>',i[len(i)-1]):
print(i[:len(i)-1].replace('><',',').replace(':<',',').replace(' <',','))
else:
print(i.replace(':',','))

⑦ python 分割列表的幾種方法

def groups(L1,len1):
groups=zip(*(iter(L1),)*len1)
L2=[list(i) for i in groups]
n=len(L1) % len1
L2.append(L1[-n:]) if n !=0 else L2
return L2

L1=[23,26,8,9, 'AB', 'CDEF']
print(groups(L1,3)

⑧ 關於python中文件的分割

f = open('D:\\a.txt','r')
context = f.readlines()
for line in context:
print line,

以上是將a.txt的內容讀取出來並列印,建議最好能將你的文檔內容 和要實現的最終效果用圖展示出來,方便別人理解。

⑨ python中分割字元串

imkow正解,直接轉list最好,否則自己寫list comprehension其實隱含的還是把字元串當list用,多此一舉

熱點內容
隨機啟動腳本 發布:2025-07-05 16:10:30 瀏覽:520
微博資料庫設計 發布:2025-07-05 15:30:55 瀏覽:20
linux485 發布:2025-07-05 14:38:28 瀏覽:300
php用的軟體 發布:2025-07-05 14:06:22 瀏覽:751
沒有許可權訪問計算機 發布:2025-07-05 13:29:11 瀏覽:428
javaweb開發教程視頻教程 發布:2025-07-05 13:24:41 瀏覽:691
康師傅控流腳本破解 發布:2025-07-05 13:17:27 瀏覽:236
java的開發流程 發布:2025-07-05 12:45:11 瀏覽:681
怎麼看內存卡配置 發布:2025-07-05 12:29:19 瀏覽:279
訪問學者英文個人簡歷 發布:2025-07-05 12:29:17 瀏覽:829