
工具/原料
python3.1.6
#pycharm
##方法/步驟
## 針對字串:將某個字串插入到後面字串所有的字元中間,拼接成一個新字串。 s = '**'.join('good123')print(s)

#print('***************切片*******************')s = 'good_make_dog_love_pig'c = s[-1] # 根據下標查詢對應的字符,如果從左邊數,從0開始。如果從右邊數,從-1開始。 print(c)

# s[x:y:z] 從第x個字元開始,查詢到第y個字元(不包含y),z是步長,步長預設是1。 s = 'good_make_dog_love_pig'res = s[0:10:2]print(res, type(res))

s = 'good_make_dog_love_pig'# s[x:y :z] 從第x個字元開始,查詢到第y個字元(不包含y),z是步長,步長預設是1。 res = s[0:10:2]print(res, type(res))

#res = s[-1::-1] # 步長為負數,代表從右往左查詢print(res, type(res))

#print('***********編碼**** *********')a = ord('a') # 查詢某個字元對的ASCII碼print(a, type(a))

c = chr(97) # 根據編碼查詢對應的字元(ASCII)print(c)c = 'h'print(chr(ord(c) 1))print('給定2個小寫字母,a

END
注意事項
第七個步驟要引入random模組,否則報錯。
相關教學推薦:
Python影片教學#
以上是零基礎學python之str怎麼用的詳細內容。更多資訊請關注PHP中文網其他相關文章!