How to swap the positions of two adjacent characters in python

String slicing can be used to exchange the positions of two adjacent characters in Python: str = "Python" str = str[1] + str[0] + str[2:] print(str) After the exchange is completed, the output is: ytonsP

Guess you like

Origin blog.csdn.net/weixin_42592399/article/details/129445555