ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print('a' 'b' * 2, ('a' 'b') * 2, 'ab' * 0 == '', 'x' * 3 + 'y' * 2)- A. abb abab True xxxyy
- B. abab abab False xxxyy
- C. abab abab True xxxyy
- D. abab abb True xxxyy
Correct answer: C. abab abab True xxxyy
Adjacent string literals are joined at compile time before the * operator applies, so 'a' 'b' * 2 is 'abab'. Multiplying by zero gives an empty string.
More Python Programming questions
- What is printed? python print('%.2f' % 2.675, '%.2f' % 2.665, round(2.665, 2), format(2.5, '.0f'), format(0.125, '.2f'))
- What is printed? python print(0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6, 0.1 + (0.2 + 0.3) == 0.6)
- What is printed? python from decimal import Decimal print(Decimal('0.1') + Decimal('0.2') == Decimal('0.3'), Decimal(0.1) ==…
- What is printed? python from fractions import Fraction print(Fraction(1, 3) + Fraction(1, 6), Fraction(0.5), Fraction('0.1') +…
- What is printed? python print(int('0b101', 0), int('0o17', 8), int('z', 36), int('-0'), int('+7'))
- What is printed? python print(str(True) + str(1 == 1.0), True + True, '3' True, [0] True)