Python Test 2 - Formatting

What will be the output of the following Python code snippet?

X=”hi”
print(“05d”%X)

What will be the output of the following Python code snippet?

X=”san-foundry”
print(“%56s”,X)

What will be the output of the following Python expression if x=456?

print("%-06d"%x)

What will be the output of the following Python expression if X=345?

print(“%06d”%X)

Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’?

What will be the output of the following Python expression if X = -122?

print("-%06d"%x)

What will be the output of the following Python expression if the value of x is 34?

print(“%f”%x)

What will be the output of the following Python expression if x=56.236?

print("%.2f"%x)

What will be the output of the following Python expression if x=22.19?

print("%5.2f"%x)

The expression shown below results in an error.

print("-%5d0",989)

Schreibe einen Kommentar