How to Make New String from Characters in Python


In this example we will show how to create a new string from the first 3 and last 3 characters of the given string.

Source Code

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

str = input("Please input the string: ")
newStr = str[0:3] + str[-3:]
print("The new string is: ", newStr)

Output:

Please input the string: Hello World
The new string is: Helrld
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments