Friday , September 20 2024

The following code: print(3 * ‘abc’ + ‘xyz’) prints:

Questions BankCategory: Python Essentials 2The following code: print(3 * ‘abc’ + ‘xyz’) prints:
The following code:

print(3 * 'abc' + 'xyz')
 

prints:
  • abcabcxyzxyz
  • abcabcabcxyz
  • xyzxyzxyzxyz
  • abcxyzxyzxyz

Explanation: The * and + operators replicate and concatenate when used with strings. The first operation 3 * ‘abc’ returns a string that contains abcabcabc. Then the second operation + ‘xyz’ concatenates xyz to the previous string. The resulting string abcabcabcxyz is printed in the console.

More Questions: Python Essentials 2 – Module 2 Test