0% found this document useful (0 votes)
13 views2 pages

Python String Manipulation Programs

Uploaded by

Manha Kar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Python String Manipulation Programs

Uploaded by

Manha Kar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q1.

Extract Username from Email

Write a program that takes an email address as input and prints only the username (part before @).

Input: student123@[Link]

Output: student123

Q2. Reverse Every Word

Write a program to reverse each word of a given string using slicing.

Input: "Hello World"

Output: "olleH dlroW"

Q3. Palindrome Check

Write a program to check whether a given string is a palindrome using slicing.

Input: "MADAM"

Output: Palindrome

Q4. Extract Middle Characters

Write a program that takes a string and prints the middle character(s).

 If the string length is odd → print 1 middle character.

 If even → print 2 middle characters.

Input: "PYTHON"

Output: "TH"

Q5. Encrypt with Slicing

Write a program that encrypts a word by reversing the first half and second half separately.

Input: "EDUCATION"

Output: "UDEONITAC"

Q6. Last n Characters


Write a program that asks the user for a string and an integer n, then prints the last n characters of
the string.

Input: "COMPUTER", n=3

Output: "TER"

Q7. Remove First and Last Character

Write a program to print a new string after removing the first and last character using slicing.

Input: "PYTHON"

Output: "YTHO"

Q8. Slice and Swap

Write a program that takes a string, splits it into two halves, and then swaps them.

Input: "HELLO"

Output: "LOHEL"

You might also like