How to output numbers in python?

You can use the print function in Python to display numbers. For example:

age = 25

print(age)  # 输出25

If you want to output multiple numbers, you can separate them with commas. For example:

x = 10

y = 20

print(x, y)  # 输出10 20

To format the output of numbers, you can use the formatting method of strings. For example:

num = 3.14159

print("Pi的值是: {:.2f}".format(num))  # 输出Pi的值是: 3.14

In the above example, “{:.2f}” is a part of the formatting string that indicates formatting num as a floating point number with 2 decimal places.

bannerAds