Python | print() function

Python | print() function

In Python, the print() function is used to display text on the screen. It can be used to print text, variables, and the results of mathematical operations.

Here are a few examples of how to use the print() function:


print("Hello, World!") # Prints the string "Hello, World!"

x = 5
y = 10
print(x + y) # Prints the result of x + y (15)

name = "Alice"
print("My name is", name) # Prints "My name is Alice"

Output:

Hello, World!
15
My name is Alice

You can also use print() function to print multiple values by using a comma to separate them.

x = 5
y = 10
print(x, y) # Prints 5 10

In python 3, print() is a function and it accepts multiple arguments and you can use the sep parameter to specify the separator between the arguments.

x = 5
y = 10
print(x, y, sep=',') # Prints 5,10

Output:

5,10

You can also use the end parameter to specify the character that should be printed after the last argument. By default, it is a newline character.

x = 5
y = 10
print(x, y, end='. ')
print(x*y) # Prints 5,10. 50

Output:

5,10. 50

print() is a very useful function in Python and you will use it frequently while programming.

Leave a Reply

Your email address will not be published.

📢 Need further clarification or have any questions? Let's connect!

Connect 1:1 With Me: Schedule Call


If you have any doubts or would like to discuss anything related to this blog, feel free to reach out to me. I'm here to help! You can schedule a call by clicking on the above given link.
I'm looking forward to hearing from you and assisting you with any inquiries you may have. Your understanding and engagement are important to me!

This will close in 20 seconds