0% found this document useful (0 votes)
5 views

Strings

Python strings questionaire

Uploaded by

smita Rangdal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Strings

Python strings questionaire

Uploaded by

smita Rangdal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Write a Python program to calculate the length of a string.

2. 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.
Sample String : 'codemania'
Expected Result : 'coia'
Sample String : 'co'
Expected Result : 'coco'
Sample String : ' c'
Expected Result : Empty String

3. Write a Python program to get a string from a given string where all occurrences of
its first char have been changed to '$', except the first char itself.
Sample String : 'restart'
Expected Result : 'resta$t'

4. Write a Python program to remove the nth index character from a nonempty string.

5. Write a Python script that takes input from the user and displays that input back in
upper and lower cases.

6. Write a Python function to reverse a string.

7. Write a Python program to count repeated characters in a string.


Sample string: 'thequickbrownfoxjumpsoverthelazydog'
Expected output :
o4
e3
u2
h2
r2
t2

8. Write a Python program to print the square and cube symbol in the area of a
rectangle and volume of a cylinder.
Sample output:
The area of the rectangle is 1256.66cm2
The volume of the cylinder is 1254.725cm3

9. Write a Python program to print the index of the character in a string.


Sample string: codemania
Expected output:
Current character c position at 0
Current character o position at 1
Current character d position at 2
Current character i position at 8
Current character a position at 9
10. Write a Python program to check if a string contains all letters of the alphabet.

11. Write a Python program to remove spaces from a given string.

12. Write a Python program to capitalize first and last letters of each word of a given
string.

13. Write a Python program to create a string from two given strings using
concatenation.

14. Write a Python program to count Uppercase, Lowercase, special character and
numeric values in a given string.

You might also like