Showing posts with label Split. Show all posts
Showing posts with label Split. Show all posts

Monday, September 14, 2026

Python split() Method Quiz

Python:

Quiz 1: Custom Delimiters
What will be the output of the following code?

data = "apple,banana,cherry"
print(data.split(","))
  • A) ["apple", "banana", "cherry"]

  • B) "apple" "banana" "cherry"

  • C) ["apple,banana,cherry"]

  • D) Error

Quiz 2: Handling Extra Whitespace What will be the output of the following code?

text = "Hello World Python"
print(text.split())
  • A) ['Hello', '', '', 'World', '', 'Python']

  • B) ['Hello', 'World', 'Python']

  • C) ['Hello World Python']

  • D) Error


Quiz 3: The Opposite of Split What will be the output of the following code?

words = ["Python", "is", "fun"]
print(" ".join(words))
  • A) ["Python is fun"]

  • B) Python, is, fun

  • C) Python is fun

  • D) ['Python', 'is', 'fun']


-------------

1. What is the output of print("Python is easy".split())?
   A. Python is easy
   B. ['Python', 'is', 'easy']
   C. ['Python', 'is easy']
   D. ['Python is easy']

2. What is the output of print("a,b,c".split(","))?
   A. ['a', ',b', ',c']
   B. ['a', 'b', 'c']
   C. ['a', 'b,c']
   D. ['a,b,c']

3. What is the output of print("one two three".split(" ", 1))?
   A. ['one two three']
   B. ['one two', 'three']
   C. ['one', 'two', 'three']
   D. ['one', 'two three']

4. What is the output of print("hello".split("l"))?
   A. ['he', '', 'o']
   B. ['he', 'llo']
   C. ['hel', 'o']
   D. ['hello']

5. What is the output of print(" Python quiz ".split())?
   A. ['Python', 'quiz']
   B. [' Python', 'quiz ']
   C. ['Python', '', 'quiz']
   D. ['', 'Python', '', '', 'quiz', '']