python,一些常用的方法

2021-10-09 15:54:25 字數 1133 閱讀 5832

try:

'**'

except:

'如果try內報錯,執行這裡的**'

else:

'如果try內不報錯,執行這裡的**'

except後可以跟具體的異常名字,來精確的決定哪些報錯才會執行except內的**

1. 簡單粗魯的字串拼接

1 name = "abc"

2 age = 25

3 info = "the name is "+name +"\nthe age is " + str(age)

4 print(info)

執行結果:

執行結果:

執行結果:

Python列表的一些常用方法

1.l.index value begin end begin開始索引,end是結束索引,返回value值得索引下標,如果value值不存在,則觸發valueerror錯誤 2.l.count x 返回列表中x元素的個數 3.l.insert index,value 將value值插入到index下...

CString的一些常用方法

cstringleft int ncount const 從左邊1開始獲取前ncount 個字元 cstringmid int nfirst const 從左邊第ncount 1 個字元開始,獲取後面所有的字元 cstringmid int nfirst,int ncount const 從左邊第n...

NSString的一些常用方法

nsstring 方法名名詞開頭的不會改變當前物件的內容,動詞開頭會改變物件的內容 把字串str通過字符集 分割 nsstring str aaaa a a s d sd.exe nsarray arr str componentsseparatedbycharactersinset nschara...