Python Practice › String Programs › Program 48

First 2 and last 2 characters

EasyString Programs · 48 of 106

Write a Python program to build a string from the first 2 and last 2 characters.

Advertisement
Input
"Sqatools"
Output
Sqls

Approach

  1. Join [:2] and [-2:].

Solution

Python
text = "Sqatools"print(text[:2] + text[-2:])
Output
Sqls
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs