Get the App
SLTechnology News&Howtos  ›  Development  › 

How python reverses string and list

Shulou Source: shulou.com Published: 2022-06-01 06:20:22 10月03日 Update

This article mainly introduces how python reverses string and list, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Four ways of reversing string/list reverse the list itself testList = [1dje 3je 5] testList.reverse () print (testList) #-> [5,3,1] reverse for element in reversed when iterating in a loop ([1dre 3p5]): print (element) # 1-> 5pm 2-> 3pm 3-> 1 reverses a string "Test Python" [::-1]

This makes the output "nohtyP tseT"

Use slices to reverse the list [1, 3, 5] [::-1]

The above command outputs [5, 3, 1].

Thank you for reading this article carefully. I hope the article "how python reverses string and list" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles output value interest at the same time commands characters strings methods more friends knowledge editing industry information information channels face channels references learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi macOS Huawei Microsoft