Learn with Yasir

Share Your Feedback

Python Strings: True or False Practice Questions with Answers

Test your understanding of Python strings with true or false questions. Strengthen your concepts on string methods, formatting, and operations through quick evaluations and instant answers.

๐Ÿ” True or False

๐ŸŸข Beginner

  1. You can use both single (' ') and double (" ") quotes to define a string in Python.
  2. Answer

    โœ… True โ€“ Python allows strings to be defined using either single or double quotes.


  3. The len() function is used to determine the length of a string.
  4. Answer

    โœ… True โ€“ The built-in len() function returns the number of characters in a string.


  5. The upper() method changes all the characters in a string to lowercase.
  6. Answer

    โŒ False โ€“ The upper() method converts all characters in a string to uppercase.


  7. You can concatenate strings using the + operator in Python.
  8. Answer

    โœ… True โ€“ The + operator is used to join or concatenate two or more strings.


  9. The strip() method removes characters from the middle of a string.
  10. Answer

    โŒ False โ€“ The strip() method removes leading and trailing whitespace from a string.


  11. String indexing in Python starts from 1.
  12. Answer

    โŒ False โ€“ Python uses zero-based indexing, so the first character of a string is at index 0.


  13. The replace() method can be used to change specific parts of a string.
  14. Answer

    โœ… True โ€“ The replace() method returns a new string with all occurrences of a substring replaced.


  15. You cannot loop through a string using a for loop.
  16. Answer

    โŒ False โ€“ Strings are iterable in Python, so you can loop through them character by character.


  17. The in keyword checks whether a substring exists in a string.
  18. Answer

    โœ… True โ€“ The in keyword returns True if the specified substring is found in the string.


  19. Strings in Python support slicing.
  20. Answer

    โœ… True โ€“ Python allows slicing of strings using the syntax string[start:stop:step].


  21. Triple quotes are used for multi-line strings in Python.
  22. Answer

    โœ… True โ€“ Triple single (''') or double quotes (""") can define multi-line strings.


  23. The find() method returns -1 if the substring is not found.
  24. Answer

    โœ… True โ€“ The find() method returns the lowest index of the substring, or -1 if not found.


  25. Python allows escape characters like \n for new lines and \t for tabs.
  26. Answer

    โœ… True โ€“ Python uses backslash (\) escape sequences such as \n for newline and \t for tab.


  27. The `split()` method modifies the original string in-place.
  28. Answer

    โŒ False โ€“ The `split()` method returns a new list and does not alter the original string.


  29. The `partition()` method always returns a tuple with exactly three elements.
  30. Answer

    โœ… True โ€“ Regardless of whether the separator is found, `partition()` always returns a 3-part tuple.


  31. The `replace()` method can be used to substitute multiple different substrings at once.
  32. Answer

    โŒ False โ€“ The `replace()` method handles only one substring replacement at a time unless nested or chained.


  33. The `find()` method is case-sensitive.
  34. Answer

    โœ… True โ€“ The `find()` method distinguishes between uppercase and lowercase letters during a search.


  35. If the separator is not found, `partition()` returns the original string and two empty strings.
  36. Answer

    โœ… True โ€“ When the separator is missing, `partition()` returns (original_string, '', '').


๐ŸŸก Intermediate

  1. Strings in Python are mutable.
  2. Answer

    โŒ False โ€“ Strings in Python are immutable, meaning their content cannot be changed after creation.


  3. You can change a specific character in a string using indexing.
  4. Answer

    โŒ False โ€“ Strings are immutable in Python, so you cannot change characters via indexing.


๐Ÿ”ด 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