ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(sum(1 for c in 'a1b22c333' if c.isdigit()), ''.join(c for c in 'a1b22c333' if c.isalpha()), int(''.join(c for c in 'a1b22' if c.isdigit())) + 1)- A. 6 abc 122
- B. 5 abc 123
- C. 6 a1b 123
- D. 6 abc 123
Correct answer: D. 6 abc 123
Six characters are digits in 'a1b22c333', the letters are abc, and the digits of 'a1b22' form 122, which is 123 after adding one.
More Python Programming questions
- What is printed? python print(str(0.1 3), repr(0.1 3) == '0.30000000000000004', 0.1 3 == float(repr(0.1 3)))
- What is printed? python print(10-1 + 10-1 + 10-1 == 0.3, 1/10 + 1/10 + 1/10 == 0.3, 10-1 == 1/10)
- What is printed? python print(sorted([3, 1, 2], reverse=True) == [3, 2, 1], [3, 1, 2][::-1], sorted('cab')[::-1])
- What is printed? python print(int(str(7) 3) 2 % 10, 111 2, (11 2) 10 + 1)
- What is printed? python n = float('nan') print(n in [n], float('nan') in [n], n == n, [n] == [n])
- What is printed? python print(0.1 + 0.2 in [0.3], 0.3 in [0.1 + 0.2], round(0.1 + 0.2, 1) in [0.3])