Saturday, September 12, 2026

Python String Format Quizzes

Python String Format Quizzes


1. What is the output? print("python".upper())

   A. PYTHON

   B. python

   C. Python

   D. pYTHON


2. What is the output? print("PYTHON".lower())

   A. pYthon

   B. python

   C. PYTHON

   D. Python


3. What is the output? print("hello world".title())

   A. Hello world

   B. HELLO WORLD

   C. hello world

   D. Hello World


4. What is the output? print("hello".capitalize())

   A. hello

   B. HELLO

   C. hELLO

   D. Hello


5. What is the output? print("PyThOn".swapcase())

   A. python

   B. PyThOn

   C. PYTHON

   D. pYtHoN


6. What is the output? print("banana".find("na"))

   A. 2

   B. 4

   C. 1

   D. 3


7. What is the output? print("banana".count("a"))

   A. 3

   B. 4

   C. 1

   D. 2


8. What is the output? print("python".startswith("py"))

   A. False

   B. 0

   C. None

   D. True


9. What is the output? print("report.pdf".endswith(".pdf"))

   A. None

   B. False

   C. True

   D. pdf


10. What is the output? print("hello world".replace("world", "Python"))

   A. helloPython

   B. hello Python

   C. hello world

   D. Python world


11. What is the output? print("a,b,c".split(","))

   A. ('a', 'b', 'c')

   B. a b c

   C. ['a', 'b', 'c']

   D. ['a,b,c']


12. What is the output? print("-".join(["2026", "09", "12"]))

   A. 2026/09/12

   B. 20260912

   C. 2026-09-12

   D. ['2026-09-12']


13. What is the output? print("Python123".isalnum())

   A. True

   B. False

   C. Python

   D. 123


14. What is the output? print("12345".isdigit())

   A. True

   B. 5

   C. 12345

   D. False


15. What is the output? print("abc".center(7, "-"))

   A. abc----

   B. abc

   C. ---abc-

   D. --abc--


16. What is the output? print("42".zfill(5))

   A. 00042

   B. 42000

   C. 0042

   D. 42.000


17. What is the output? print("abc123".isalpha())

   A. False

   B. abc

   C. 123

   D. True


18. What is the output? print("Hello".find("x"))

   A. -1

   B. None

   C. 0

   D. 1


19. What is the output? print("hello\tworld".expandtabs(4))

   A. hello\tworld

   B. helloworld

   C. hello world

   D. hello world

No comments: