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 CodeMeaningExample
\nNew lineprint("Hello\nWorld")
\tTab spaceprint("A\tB\tC")
\"Double quote inside stringprint("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

FeatureExample
Print textprint("Hello")
Print numbersprint(100)
Print variableprint(x)
Format messageprint(f"Value is {x}")
New line\n
Custom endprint("Hello", end="***")
Separatorprint(a, b, sep=",")

You may also like...