Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

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

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')

Python String Methods

 Python String Methods Quiz

1. What is the output? s = "Hello World" print(s.lower())

   A. Hello World

   B. hello world

   C. Hello world

   D. HELLO WORLD


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

   A. 2 4

   B. 1 4

   C. 2 3

   D. 1 3


3. What is the output? s = "hello" print(s.count("l"))

   A. 1

   B. 2

   C. 0

   D. 3


4. What is the output? s = " Python " print(s.strip())

   A. 'Python '

   B. 'Python'

   C. ' Python'

   D. ' Python '


5. What is the output? s = "a,b,c" print(s.split(","))

   A. a-b-c

   B. ['a,b,c']

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

   D. ['a', 'bc']


6. What is the output? words = ["Python", "is", "fun"] print("-".join(words))

   A. ['Python-is-fun']

   B. Python is fun

   C. Python-is-fun

   D. Python--is--fun


7. What is the output? s = "abc123" print(s.isalnum(), s.isalpha(), s.isdigit())

   A. False True False

   B. True True True

   C. True False False

   D. False False True


8. What is the output? s = "Python" print(s.startswith("Py"), s.endswith("on"))

   A. True True

   B. True False

   C. False False

   D. False True


9. What is the output? s = "hello world" print(s.title(), s.capitalize())

   A. HELLO WORLD Hello world

   B. Hello world Hello World

   C. hello world Hello World

   D. Hello World Hello world


10. What is the output? s = "42" print(s.zfill(5))

   A. 42

   B. 000042

   C. 42000

   D. 00042

Python List Methods Quiz

 Python List Methods Quiz


1. What is the output? numbers = [10, 20, 30] numbers.append([40, 50]) print(numbers)

   A. [10, 20, [40, 50], 30]

   B. [40, 50, 10, 20, 30]

   C. [10, 20, 30, [40, 50]]

   D. [10, 20, 30, 40, 50]


2. What is the output? x = [1, 2, 3] x.insert(1, 99) print(x)

   A. [1, 99, 2, 3]

   B. [1, 2, 3, 99]

   C. [1, 2, 99, 3]

   D. [99, 1, 2, 3]


3. What is the output? x = [5, 10, 5, 20] x.remove(5) print(x)

   A. [10, 5, 20]

   B. [5, 10, 5, 20]

   C. [10, 20]

   D. [5, 10, 20]


4. What is the output? x = [10, 20, 30] y = x.pop() print(x, y)

   A. [10, 20, 30] None

   B. [10, 20] 30

   C. [20, 30] 10

   D. [10, 30] 20


5. What is the output? x = [30, 10, 20] x.sort(reverse=True) print(x)

   A. [30, 20, 10]

   B. [20, 10, 30]

   C. [30, 10, 20]

   D. [10, 20, 30]