How to Form a New-Order String in Python


In this example, we will learn how to exchange the first character of a string with the last character and form a new string.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

str = input("Please input a string: ")
newStr = str[-1] + str[1:-1] + str[0]
print("After exchanging: ", newStr)

Output:

Please input a string: hello
After exchanging: oellh
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments