Single Choice Not Set

QWhat will be the output after the following statements?
x = 'Python %.1f or Python %.2f' %(2.7, 3.51)
print(x)

ID: #3608 String Formatting in Python 414 views
Question Info
#3608Q ID
Not SetDifficulty
String Formatting in PythonTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A Python 3.51 or Python 2.7
  • B Python 2 or Python 3
  • C Python 2.7 or Python 3.5
  • D Python 2.7 or Python 3.51
Correct Answer

Explanation

Let's evaluate the code:

  • %.1f for the first placeholder: 2.7 formatted with one digit after the decimal point is 2.7.
  • %.2f for the second placeholder: 3.51 formatted with two digits after the decimal point is 3.51.

So, the output of the code will be:


Python 2.7 or Python 3.51

Share This Question

Challenge a friend or share with your study group.