python中字符串如何反轉?
- 電腦
- 關注:1.36W次
怎樣在 python 中將字符串“hello word”反轉打印呢?介紹幾種方法供大家參考。
操作方法
(01)切片法
(02)>>> x27;hello world'[::-1]'dlrow olleh'
(03)切片的擴展語法。步長為-1, 即字符串的翻轉
方法/步驟2
(01)for循環輸出
(02)string ='hello world'print ''(string[i] for i in range(len(string)-1, -1, -1))dlrow olleh
- 文章版權屬於文章作者所有,轉載請註明 https://miaozhigu.com/sm/diannao/qyjykg.html