How to print output in python

In Python, you can use the print() function to display output. Just input the content you want to display within parentheses, separated by commas. For example:

print("Hello, world!")

This will output the string “Hello, world!” to the console. You can also use multiple parameters and separate them with commas when printing.

name = "Alice"
age = 25
print("My name is", name, "and I am", age, "years old.")

This will print “My name is Alice and I am 25 years old” to the console. You can also use special formatting strings to print the output, such as:

x = 10
y = 20
print("The value of x is {} and the value of y is {}".format(x, y))

This will output The value of x is 10 and the value of y is 20 to the console. You can specify the position where the values should be inserted using indexes in curly braces, they are inserted in order by default.

x = 10
y = 20
print("The value of y is {1} and the value of x is {0}".format(x, y))

This will print The value of y is 20 and the value of x is 10 to the console. There are also many other formatting options that you can find more information about in the documentation.

bannerAds