前往
大廳
主題

常用函數01

ww880816 | 2023-06-09 22:53:40 | 巴幣 0 | 人氣 113

常用函數01
1 . count - 用於搜索字串內使用多少次關鍵字
count(搜索的字串 , 從第幾字個開始找 , 到第幾個字結束 )
ctr = 'IKLeg_L'
keyword = 'L'
ans = ctr.count(keyword,0,len(ctr))
print(ans)  #輸出結果:2


2 . replace - 將指定的字替換成指定的字
replace( 要被替換的字 ,新的字)
selection = 'Leg_IK_L'
new = selection.replace('L','R')
print(new) #輸出結果:Reg_IK_R


3 . split - 以一個東西為基準拆分一個字串
split(當作基準的東西)
selection = 'Leg_IK_L'
new = selection.split('_')
print(new) #輸出結果:['Leg', 'IK', 'L']


4 . append - 將東西加入指定清單
append(要加入的東西)
my_list = []
print(my_list) #輸出結果:[]
selection = 'Leg_IK_L'
my_list.append(selection)
print(my_list) #輸出結果:['Leg_IK_L']



5 . len - 可返回字串的個數或長度
len(要查詢的東西)
my_list = [1,2,3]
print len(my_list) #輸出結果:3
my_str = 'python'
print len(my_str) #輸出結果:6



創作回應

更多創作