熱線電話:13121318867

登錄
首頁精彩閱讀python實現每次處理一個字符的三種方法
python實現每次處理一個字符的三種方法
2017-08-30
收藏

python實現每次處理一個字符的三種方法

這篇文章主要介紹了python實現每次處理一個字符的三種方法,是非常實用的字符串操作技巧,需要的朋友可以參考下

本文實例講述了python每次處理一個字符的三種方法。
具體方法如下:    
a_string = "abccdea"
 
print 'the first'
for c in a_string:
  print ord(c)+1
 
    
print "the second"  
result = [ord(c)+1 for c in a_string]
print result
 
print "the thrid"
 
def do_something(c):
  return ord(c)+1
 
result = map(do_something ,a_string)
print result

打印出的結果如下:
    
the first
98
99
100
100
101
102
98
the second
[98, 99, 100, 100, 101, 102, 98]
the thrid
[98, 99, 100, 100, 101, 102, 98]
希望本文所述對大家的Python程序設計有所幫助。


數據分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數據分析師資訊
更多

OK
客服在線
立即咨詢
日韩人妻系列无码专区视频,先锋高清无码,无码免费视欧非,国精产品一区一区三区无码
客服在線
立即咨詢