Python Print() Statement: How to Print with Examples

Created with Sketch.

Python print() Statement: Printing Examples

In Python, the print() statement is a fundamental function used for displaying messages on the screen. This versatile function can be applied to print strings, objects, or a combination thereof. Here are several examples to illustrate the usage of the print() statement:

1. Printing a Simple String:

print("Hello, World!")

Output:

Hello, World!

2. Printing Multiple Strings:

print("Python", "Programming", "Example")

Output:

Python Programming Example

3. Formatting Output:

name = "John"
age = 25
print("Name:", name, "Age:", age)

Output:

Name: John Age: 25

4. Printing with Separator:

print("Apple", "Banana", "Orange", sep=", ")

Output:

Apple, Banana, Orange

5. Printing with End Character:

print("Hello", end=" ")
print("World!")

Output:

Hello World!

6. Formatting Numbers:

x = 10
y = 3.14
print(f"Value of x: {x}, Value of y: {y:.2f}")

Output:

Value of x: 10, Value of y: 3.14

7. Printing Multiple Lines:

print("Line 1\nLine 2\nLine 3")

Output:

Line 1
Line 2
Line 3

8. Printing with Escape Characters:

 
print("This is a\tTab\tSeparated\tString")

Output:

This is a    Tab     Separated       String

These examples showcase the versatility of the print() statement in Python, from basic string printing to more advanced formatting techniques. Feel free to experiment and integrate these concepts into your Python programs.

Leave a Reply

Your email address will not be published. Required fields are marked *