ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
s = 'a,b;c'
print(s.split(',;'), s.replace(';', ','), s.split(';'))
  1. A. ['a', 'b;c'] a,b,c ['a,b']
  2. B. ['a,b;c'] a,b;c ['a,b', 'd']
  3. C. ['a,b;c'] a,b,c ['a,b', 'c']
  4. D. ['a', 'b', 'c'] a,b,c ['a,b', 'c', 'd']

Correct answer: C. ['a,b;c'] a,b,c ['a,b', 'c']

split looks for the whole separator ',;', which does not occur, so the string stays whole. replace changes every ';' to ',', and split(';') cuts at the semicolon.

More Python Programming questions

Exams that ask this topic