Strings · Class 11 · CBSE · Science Computer Science

What is printed by the following Python code? s = " Data Science "; print(s.strip().replace(" ", "").lower())

Practice question from Strings (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

medium · MCQ · Q-C714C8

What is printed by the following Python code? s = " Data Science "; print(s.strip().replace(" ", "_").lower())

  1. A.Data_Science
  2. B.data_scienceCorrect answer
  3. C.data_science
  4. D.data science

Solution

strip() removes the leading and trailing spaces, replace() changes the internal space to an underscore, and lower() converts all letters to lowercase. Therefore, the output is data_science.

More from Strings

All of Strings

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed