Python Output

🖨️ Python Output (Print Function)

In Python, output is shown using the print() function. It displays text, numbers, variables, and results on the screen.


✅ Basic Print Example

print("Hello, Python!")

Output:

Hello, Python!

🧩 Printing Numbers

print(10)
print(20 + 30)

Output:

10
50

🧩 Printing Variables

name = "Vipul"
age = 25
print(name)
print(age)

Output:

Vipul
25

🧩 Printing Text with Variables

Method 1: Using Comma ,

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

Method 2: Using f-Strings (Recommended)

name = "Vipul"
age = 25
print(f”My name is {name} and I am {age} years old.”)

Method 3: Using format()

print("My name is {} and I am {} years old.".format(name, age))

🧩 Printing Multiple Lines

print("Python is fun!")
print("Learning step by step!")

🧩 Escape Characters

Escape characters allow printing special symbols.

Escape Code Meaning Example
\n New line print("Hello\nWorld")
\t Tab space print("A\tB\tC")
\" Double quote inside string print("He said \"Hi\"")

Example:

print("Hello\nPython")
print("Name:\tVipul")

🧩 Changing the Default End (end parameter)

By default, print ends with a newline. You can change it:

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

Output:

Hello World

🧩 Changing Separator (sep parameter)

print(10, 20, 30, sep="-")

Output:

10-20-30

🎯 Summary

Feature Example
Print text print("Hello")
Print numbers print(100)
Print variable print(x)
Format message print(f"Value is {x}")
New line \n
Custom end print("Hello", end="***")
Separator print(a, b, sep=",")

You may also like...