Python Practice › String Programs › Program 48
First 2 and last 2 characters
Write a Python program to build a string from the first 2 and last 2 characters.
Input
"Sqatools"
Output
Sqls
Approach
- Join
[:2]and[-2:].
Solution
text = "Sqatools"print(text[:2] + text[-2:])Output
Sqls
Learn the concept
New to this topic? Read the lesson, then come back.