Python String Tutorial
Exercise 1: Create a string made of the first, middle and
last character
Write a program to create a new string made of an input string’s first, middle, and last character.
Given:
str1 = "James"
Expected Output:
Jms
Exercise 2: Create a string made of the middle three
characters
Write a program to create a new string made of the middle three characters of an input string.
Given:
Case 1
str1 = "JhonDipPeta"
Output
Dip
Case 2
str2 = "JaSonAy"
Output
Son
Exercise 3: Append new string in the middle of a given
string
Given two strings, s1 and s2. Write a program to create a new string s3 by appending s2 in the
middle of s1.
Given:
s1 = "Ault"
s2 = "Kelly"
Expected Output:
AuKellylt
Exercise 4: Create a new string made of the first, middle,
and last characters of each input string
Given two strings, s1 and s2, write a program to return a new string made of s1 and s2’s first,
middle, and last characters.
Given:
s1 = "America"
s2 = "Japan"
Expected Output:
AJrpan
Exercise 5: Arrange string characters such that lowercase
letters should come first
Given string contains a combination of the lower and upper case letters. Write a program to
arrange the characters of a string so that all lowercase letters should come first.
Given:
str1 = PyNaTive
Expected Output:
yaivePNT
Exercise 5: Count all letters, digits, and special symbols
from a given string
Given:
str1 = "P@#yn26at^&i5ve"
Expected Outcome:
Total counts of chars, digits, and symbols
Chars = 8
Digits = 3
Symbol = 4
Exercise 6: Create a mixed String using the following
rules
Given two strings, s1 and s2. Write a program to create a new string s3 made of the first char of
s1, then the last char of s2, Next, the second char of s1 and second last char of s2, and so on. Any
leftover chars go at the end of the result.
Given:
s1 = "Abc"
s2 = "Xyz"
Expected Output:
AzbycX