Exam4Training

What is the expected output of the following code?

What is the expected output of the following code?

z = y = x = 1

print(x, y, z, sep=’*’)
A . x*y*z
B. 111*
C. x y z
D. 1*1*1
E. 1 1 1
F. The code is erroneous.

Answer: D

Explanation:

Topic: multiple assignment print() with sep parameter

Try it yourself:

z = y = x = 1

print(x, y, z, sep=’*’) # 1*1*1

print(x, y, z, sep=’ ‘) # 1 1 1

print(x, y, z) # 1 1 1

The print() function has a sep parameter which stands for separator.

The default value of the sep parameter is a space character.

You can change it to anything you want.

Exit mobile version