How python reverses string and list
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!