ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'a b c'
print(s.split(' '), s.split(), len(s.split(' ')) - len(s.split()))- A. ['a', 'b', '', 'c'] ['a', 'b', 'c'] 1
- B. ['a', 'b', 'c'] ['a', 'b', 'c'] 0
- C. ['a', 'b', '', 'c'] ['a', 'b', 'c'] 2
- D. ['a', 'b', 'c'] ['a', 'b'] 1
Correct answer: A. ['a', 'b', '', 'c'] ['a', 'b', 'c'] 1
split(' ') keeps the empty field between the two spaces, so it has four pieces. split() with no argument removes every empty field and returns three words, which gives a difference of 1.
More Python Programming questions
- What is printed? python x = 0 for i in range(1, 9): x ^= i print(x, 5 ^ 9 ^ 5, (1 << 3) - 1 & 6)
- What is printed? python s = 'mississippi' print(s.count('ss'), s.count('issi'), s.index('s', 3), s.rindex('i', 0, 5))
- What is printed? python import math print(math.isqrt(10 12), math.isqrt(2 10 12) 2 <= 2 10 12)
- What is printed? python def fact(n): return 1 if n <= 1 else n fact(n - 1) print(len(str(fact(25))), fact(25) % 10 6 == 0, fact(25) % 7)
- What is printed? python x = 'aXbX' print(x.split('X'), x.partition('X')[0] + x.rpartition('X')[2])
- What is printed? python print(2 200 % 7 == pow(2, 200, 7), len(str(2 200)), 2 200 % 7)