歡迎來到趣知常識網!
>
怎樣在 python 中將字串“hello word”反轉列印呢?介紹幾種方法供大家參考。
(01)切片法
(02)>>> 'hello world'[::-1]'dlrow olleh'
(03)切片的擴充套件語法。步長為-1, 即字串的翻轉
(01)for迴圈輸出
(02)string ='hello world'print ''(string[i] for i in range(len(string)-1, -1, -1))dlrow olleh
圖文推薦
相關文章