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?
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?
print(" ".join(words))
A)
["Python is fun"]B)
Python, is, funC)
Python is funD)
['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', '']
1 comment:
What is the output of print("Python is easy".split())?
Whitespace splitting separates the string into three words.
What is the output of print("a,b,c".split(","))?
Each comma separates the string into another list element.
What is the output of print("one two three".split(" ", 1))?
The first split occurs after one, producing the remainder as the second element.
What is the output of print("hello".split("l"))?
Both occurrences of l are separators, leaving an empty element between adjacent separator positions.
What is the output of print(" Python quiz ".split())?
Default split() treats runs of whitespace as separators and removes their surrounding effect.
Post a Comment