Write a Python program to get a string made of the first 2 and the last 2 chars from a given a string. If the string length is less than 2, return instead of the empty string.
Answers
Answered by
6
The following codes have been written using Python.
Once we take the input, we use a conditional statement to check the count of the string, using an inbuilt function called len(), designed for the same. If the count of the string is lesser than 2, it returns an empty string. If not, it proceeds with the feature of the question, i.e., to concatenate the first two and the last two characters of the input. The retrieval of the characters is done using string slicing, i.e., using the index values of the characters to retrieve them. The new string is stored in a new variable and printed at the end.
Similar questions
India Languages,
6 hours ago
Hindi,
6 hours ago
Math,
6 hours ago
Math,
11 hours ago
History,
7 months ago