Learn with Yasir

Share Your Feedback

Python Strings Fill in the Blanks – Practice Exercises for Beginners

Practice Python string concepts with engaging fill-in-the-blank exercises. Improve your understanding of string methods, formatting, and manipulation through interactive questions with answers.

Topic: strings


🔍 Fill in the Blanks

🟢 Beginner

  1. In Python, a string is a sequence of characters enclosed in ________.
  2. Answer

    quotes

    Strings in Python are defined by enclosing characters within single ('') or double ('') quotes.


  3. The operator used to concatenate two strings in Python is ________.
  4. Answer

    +

    The '+' operator is used to concatenate (join) two or more strings in Python.


  5. To repeat a string multiple times in Python, you use the ________ operator.
  6. Answer

    *

    The '*' operator is used to repeat a string a specified number of times.


  7. The method to convert all characters of a string to uppercase is ________.
  8. Answer

    upper()

    The 'upper()' method returns a copy of the string with all characters converted to uppercase.


  9. To remove leading and trailing spaces from a string, use the ________ method.
  10. Answer

    strip()

    The 'strip()' method removes any leading and trailing characters (space is the default) from the string.


  11. The method to check if all characters in a string are digits is ________.
  12. Answer

    isdigit()

    The 'isdigit()' method returns True if all characters in the string are digits.


  13. To replace all occurrences of a substring within a string, use the ________ method.
  14. Answer

    replace()

    The 'replace()' method returns a copy of the string with all occurrences of a substring replaced with another substring.


  15. The method to split a string into a list where each word is a list item is ________.
  16. Answer

    split()

    The 'split()' method splits a string into a list where each word is a list item, using space as the default separator.


  17. To check if a string starts with a specified substring, use the ________ method.
  18. Answer

    startswith()

    The 'startswith()' method returns True if the string starts with the specified value.


  19. The method to convert the first character of each word to uppercase is ________.
  20. Answer

    title()

    The 'title()' method returns a string where the first character of each word is uppercase and the rest are lowercase.


  21. The `________` method splits a string into three parts: before, separator, and after.
  22. Answer

    partition()

    The `partition()` method splits the string at the first occurrence of the separator into a tuple containing three elements: the part before the separator, the separator itself, and the part after.


  23. To divide a string into a list using a delimiter, we use the `________` method.
  24. Answer

    split()

    The `split()` method breaks a string into a list using the specified delimiter. If no delimiter is specified, it splits on whitespace by default.


  25. The `________` method searches for a substring and returns its lowest index in the string.
  26. Answer

    find()

    The `find()` method returns the index of the first occurrence of the specified substring. If the substring is not found, it returns -1.


  27. The `________` method replaces all instances of a substring with another string.
  28. Answer

    replace()

    The `replace()` method returns a copy of the string where all occurrences of a substring are replaced with another substring.


  29. If the substring is not found, the `find()` method returns `________`.
  30. Answer

    -1

    If the `find()` method does not locate the specified substring, it returns -1, indicating no match was found.


🟡 Intermediate

🔴 Advanced



📚 Related Resources

🧠 Practice & Progress

Explore More Topics

📘 Learn Python

Tutorials, Roadmaps, Bootcamps & Visualization Projects

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




🧠 Python Advanced

Object-Oriented Programming in Python (OOP)

More...

🧠 Modules