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

Python String Exercises

The document contains a list of Python string exercises designed to practice various string manipulation techniques. Each exercise focuses on a specific task, such as creating, modifying, and analyzing strings. The exercises cover a wide range of string operations including slicing, concatenation, and formatting.

Uploaded by

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

Python String Exercises

The document contains a list of Python string exercises designed to practice various string manipulation techniques. Each exercise focuses on a specific task, such as creating, modifying, and analyzing strings. The exercises cover a wide range of string operations including slicing, concatenation, and formatting.

Uploaded by

veena.katiyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python String Exercises

1. Create a string variable with your name and print it.

2. Print the length of a given string.

3. Print the first and last character of a string.

4. Slice and print the first 3 characters of a string.

5. Slice and print the last 3 characters of a string.

6. Reverse a given string and print it.

7. Concatenate two strings and print the result.

8. Repeat a string 5 times and print it.

9. Check if the word 'Python' is in a given sentence.

10. Convert a string to uppercase.

11. Convert a string to lowercase.

12. Replace 'world' with 'Python' in the string 'Hello world'.

13. Find the index of the character 'a' in a string.

14. Count how many times the letter 'e' appears in a string.

15. Remove all spaces from a string.

16. Split a sentence into a list of words.

17. Join a list of words into a single string separated by hyphens.

18. Check if a string starts with 'Hello'.

19. Check if a string ends with '!'.

20. Capitalize the first letter of a string.

21. Swap the case of all characters in a string.

22. Center a string within 20 characters width, padded by '*'.

23. Remove leading and trailing spaces from a string.

24. Check if a string is numeric.

25. Check if all characters in a string are alphabetic.


26. Create a multi-line string and print it.

27. Format a string to include variables (e.g., name and age).

28. Get the ASCII value of a character.

29. Convert an integer ASCII value back to a character.

30. Print each character of a string on a new line using a loop.

You might also like