ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
s = 'a\tb\nc'
print(len(s), s.split(), s.split('\n'), repr(s.split()[0]))- A. 5 ['a', 'b', 'c'] ['a\tb', 'c'] 'a'
- B. 4 ['a', 'b', 'c'] ['a\tb', 'c'] 'a'
- C. 5 ['a', 'b'] ['a\tb', 'c'] 'a'
- D. 5 ['a', 'b', 'c'] ['a', 'b\nc'] 'a'
Correct answer: A. 5 ['a', 'b', 'c'] ['a\tb', 'c'] 'a'
The string has five characters: a, tab, b, newline and c. split() with no argument also splits on the tab and newline, and split('\n') splits only on the newline.
More Python Programming questions
- What is printed? python from fractions import Fraction print(Fraction(3, 6), Fraction('0.75'), Fraction(0.75), Fraction(1, 3) +…
- What is printed? python print(divmod(7, 2.5), divmod(-7.5, 2))
- What is printed? python print(0.1 + 0.1 + 0.1 == 0.3, 0.1 + 0.1 + 0.1, 0.3 == 3 0.1)
- What is printed? python print(bin(5 ^ 3), bin(-5 & 0b1111), int('-0b101', 2))
- What is printed? python print(2 -1, 2 -1074 > 0, 10 -3 == 0.001, 10 -2)
- What is printed? python print(' '.join(['a', '', 'b']), ' '.join([]) == '', '-'.join('abc'), 'x'.join(['1', '2', '3']))