ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(len('a1b22c333'.split('2')), ''.join(c for c in 'a1b22c333' if c.isdigit()), len('a1b22c333'))- A. 3 122333 8
- B. 4 122333 9
- C. 3 122333 9
- D. 3 122 9
Correct answer: C. 3 122333 9
split('2') breaks the text at each 2, giving three pieces. Joining the digits gives 122333, and the full string has nine characters.
More Python Programming questions
- What is printed? python print(0.1 + 0.1 + 0.1 == 0.3, 0.1 3, 0.3 / 0.1, int(0.3 / 0.1))
- What is printed? python print(format(0.5, '.0f'), format(1.5, '.0f'), format(2.5, '.0f'), format(-0.5, '.0f'))
- What is printed? python print('ab' 2 == 'abab', 'ab' 0 == '', 'a' 2 + 'b' 0 == 'aa', ('x' 2).count('xx'))
- What is printed? python print(int('٣٣') 2, '٣٣'.isdigit(), '٣٣'.isascii(), '3' == '٣')
- What is printed? python import math print(math.gcd(0, -5), math.gcd(-4, -6), math.lcm(0, 5), math.lcm(-4, 6))
- What is printed? python print(len('%.3f' % 260), '%.3f' % 260, '%.0f' % 1e20)