您好,登錄后才能下訂單哦!
常用:分割、長度、索引、切片 r = (1,2,3,4,5)#只讀列表元組 name = "liangml" strip username = input("user:") if username.strip() == "liangml":#strip可以將輸入前后的空格都換掉 print("welcome") split names = "liangml","tom","jack" name2 = names.split(",")#split是names拆分開來(得到一個列表) print("|".join(name2))#join是將name2結果以|形式合并到一起 print("" in name)#有沒有空格 capitalize print(name.capitalize())#capitalize是將名字的首字母大寫 format #format字符串兩種賦值方式 msg = "Hello,{name},It's been a long {age} since last time sopke...." #msg2 = msg.format(name="zhangsan",age=111) #print(msg2) msg2 = "lisi{0},dddd{1}" print(msg2.format("liangml",22)) center print(name[2:4]) print(name.center(40,"-"))#center可以指定長度,將字符串兩邊的長度均勻的分開 find print(name.find("a"))#find查找賦值中有幾個包含字符串 isdigit age = input("your age:") if age.isdigit():#isdigit判斷他是否為數字 age = int(age) else: print("invalid data type") isalnum name = "liangml!dfs" print(name.isalnum())#不容許復制里面有特殊字符 endswith、startswith print(name.endswith("dfsd")) print(name.startswith("dfsfds")) upper、lower print(name.upper().lower())#upper賦值全部大寫,lower全部變小
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。