What will be the output of `print(3 * 'AB' + 'C')` in Python?
Answer and explanation
Correct answer: C. `'ABABABC'`
- Step 1: In Python, multiplying a string by an integer replicates that string: `3 * 'AB'` produces `'ABABAB'`.
- Step 2: The addition operator concatenates `'C'` to the end, resulting in `'ABABABC'`.
Answer
`'ABABABC'`.
Why not the others: '`ABCABCABC`' replicates `'ABC'`; '`AB3C`' treats 3 as a literal character; '`6C`' attempts numerical multiplication of letters.
Practise more Python Programming, Data Structures, Algorithms, Networks and Cybersecurity.
Free questions with an explanation for every one, and full timed Saudi Secondary School Certificate mock tests.
More Python Programming, Data Structures, Algorithms, Networks and Cybersecurity questions
- What is the time complexity of searching for an element in an unsorted array of elements using linear search?
- What is the output of the following Python expression: `[x**2 for x in range(5) if x % 2 == 1]`?
- Which data structure operates on a Last-In, First-Out (LIFO) access principle?
- Which SQL clause is used to filter aggregated group records after a `GROUP BY` statement has been applied?
- What type of network topology connects all nodes to a central forwarding device such as a network switch?
- In cybersecurity, what type of malicious attack overwhelms a web server with massive volumes of traffic from multiple compromised sources to…