ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
s = 'a,b;c'
print(s.split(',;'), s.replace(';', ','), s.split(';'))- A. ['a', 'b;c'] a,b,c ['a,b']
- B. ['a,b;c'] a,b;c ['a,b', 'd']
- C. ['a,b;c'] a,b,c ['a,b', 'c']
- 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
- What is printed? python print(max(range(5), key=lambda i: (i % 3, -i)))
- What is printed? python print(sum(x x for x in range(-3, 4)), sum(abs(x) for x in range(-3, 4)))
- What is printed? python print(2 0.5 2 0.5 == 2, round(2 0.5 2 0.5, 12) == 2)
- What is printed? python print(''.join(reversed('ab' 2)), 'ab'[::-1] 2 == 'baba')
- Which operation is O(1) on average in CPython?
- A loop runs s += c for 100000 single characters in CPython. Which statement is most accurate?