Python · Question 24 · Medium

What will be the output of the following Python code?

print("  Hello World ".strip().split("o"))
  1. [' Hell', ' W', 'rld ']
  2. ['Hell', ' W', 'rld']
  3. ['Hell', ' World']
  4. ['Hell', 'W', 'rld']
Answer and explanation

Answer: B. ['Hell', ' W', 'rld']

Explanation: strip removes the outer spaces, giving "Hello World". Splitting on "o" cuts at both o's, giving 'Hell', ' W' (with its leading space) and 'rld'.

Previous: What will be the output of the following Python code? · Next: What will be the output of the following Python code?

Practise python

Try a fresh set of python questions with an explanation after every answer, free and without signing up: Python practice. Or sit a full placement mock test.

More python questions

More technical & programming practice

Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge