How to print in the console using Python?

In Python, you can use the print() function to display content on the console. Here are some examples:

Output string:

print("Hello, World!")

Show the value of the variable:

name = "Alice"

age = 25

print(name)

print(age)

Output multiple contents.

a = 10

b = 20

c = 30

print(a, b, c)

Output a formatted string:

name = "Bob"

age = 30

print("My name is %s and I'm %d years old." % (name, age))

Of course, there are more advanced ways to customize output formats, such as using f-strings (Python 3.6+) or the format() method. The examples above are just some basic usage demonstrations. The output will be displayed on the console.

bannerAds