ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(list('ab') + ['c'] * 2, 'ab' + 'c' * 2, ('a',) * 2)- A. ['a', 'b', 'c', 'c'] abcc ('a', 'a')
- B. ['a', 'b', 'cc'] abcc ('a', 'a')
- C. ['a', 'b', 'c', 'c'] acc ('a', 'a')
- D. ['a', 'b', 'c', 'c'] abcc ('a',)
Correct answer: A. ['a', 'b', 'c', 'c'] abcc ('a', 'a')
Multiplication binds tighter than +, so ['c'] * 2 gives two list items and 'c' * 2 gives 'cc'. A one-element tuple repeated twice is a two-element tuple.
More Python Programming questions
- What is printed? python print(10 18 // 7 7 + 10 18 % 7 == 10 18, (-10 18) // 7 7 + (-10 18) % 7 == -10 18, -10 18 % 7 == (-10) 18 % 7)
- What is printed? python from bisect import bisectleft, bisectright a = [1, 2, 2, 2, 3] print(bisectleft(a, 2), bisectright(a, 2)…
- What is printed? python print(str(12345)[::-1], int(str(12345)[::-1]) + 1, sum(int(d) for d in str(12345)), len(str(0)))
- What is printed? python print(0o777 ^ 0o070, 0b1111 & 0xF0 | 0x0F, 1000000 // 1e3)
- What is printed? python s = 'Straße' print(s.upper(), s.lower(), s.casefold() == 'strasse', len(s.upper()))
- What is printed? python print(0.1 0.1 == 0.01, 0.1 0.1, round(0.1 0.1, 2) == 0.01)