林佳誼w3schools字串str, format, len, slicing[::]
Python程式碼
b = "劉德華大烏龜" #python字串單或雙引號都可
# 0 1 2 3 4 5 6
# -6-5-4-3-2-1
print("字串長度:"+str(len(b))) #相同字串型態才能串接
print("反過來:"+b[::-1])
print(b[:3]) #b字串的0,1,2
print(b[-4:-1])
print(b[-8:-4])
x = '火鍋'
y = 9999
myorder = "我希望 {2} 陪我去吃 {0} 他付錢 {1}."
print(myorder.format(x, y, b))
# format的參數 0, 1, 2
306 slcing. https://jia-yi-lin.blogspot.com/2023/03/w3schoolsstr-format-len-slicing.html
回覆刪除