Showing posts with label Output. Show all posts
Showing posts with label Output. Show all posts

Friday, September 11, 2026

Python String Methods — Output Quiz

 Python String Methods — Output Quiz


1. What is the output? s = "PyThOn" print(s.swapcase())

   A. PYTHON

   B. python

   C. pYtHoN

   D. PyThOn


2. What is the output? s = "banana" print(s.find("an"), s.rfind("an"))

   A. 1 4

   B. 1 3

   C. 0 3

   D. 2 4


3. What is the output? s = "Python Python" print(s.replace("Python", "Java", 1))

   A. Python Python

   B. Java Python

   C. Python Java

   D. Java Java


4. What is the output? s = "one two three" print(s.split(" ")[1])

   A. one

   B. three

   C. two

   D. two three


5. What is the output? print("abc".isalpha(), "123".isdigit(), "abc123".isalnum())

   A. True True True

   B. True False True

   C. False True False

   D. True True False


6. What is the output? print("Hello".islower(), "HELLO".isupper(), " ".isspace())

   A. False False True

   B. True True False

   C. True False False

   D. False True True


7. What is the output? print("hi".center(6, "-"))

   A. -hi---

   B. hi----

   C. ---hi-

   D. --hi--


8. What is the output? print("42".zfill(5), "7".rjust(3, "0"))

   A. 42000 700

   B. 00042 007

   C. 00042 700

   D. 42 7


9. What is the output? s = "a-b-c" print(s.partition("-")) print(s.rpartition("-"))

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

   B. ['a', '-', 'b-c'] and ['a-b', '-', 'c']

   C. ('a-b', '-', 'c') and ('a', '-', 'b-c')

   D. ('a', 'b', 'c') and ('a', 'b', 'c')