關閉→
當前位置:趣知常識網>遊戲數碼>電腦>python中字串如何反轉?

python中字串如何反轉?

趣知常識網 人氣:1.28W

怎樣在 python 中將字串“hello word”反轉列印呢?介紹幾種方法供大家參考。

操作方法

(01)切片法

(02)>>> 'hello world'[::-1]'dlrow olleh'

python中字串如何反轉?

(03)切片的擴充套件語法。步長為-1, 即字串的翻轉

方法/步驟2

(01)for迴圈輸出

(02)string ='hello world'print ''(string[i] for i in range(len(string)-1, -1, -1))dlrow olleh

python中字串如何反轉? 第2張
TAG標籤:#python #字串 #反轉 #