πŸ“€ Python Output Functions β€” Displaying Information to the User

Introduction 🌟

Output functions allow your Python program to show messages, results, and formatted text on the screen. The primary output function in Python is print(), and it is one of the most used functions in any Python program.

Note

πŸ’‘ Think of print() as your program’s voice β€” it tells the user what is happening.

1. The print() Function β€” Basics 🧩

The print() function displays data on the console. You can print text, numbers, variables, or even formatted messages.

print_basic.py

print("Hello, Python!")

print_variables.py

name = "Sathish"
age = 25
print(name, age)

Note

πŸ“ print() automatically adds a space between values.

2. Printing Multiple Values πŸ“¦

You can print several values by separating them with commas.

multiple_values.py

print("Name:", "Sathish", "Age:", 25)

Note

πŸ’‘ Python adds spaces between values for readability.

3. Using sep and end Parameters βš™οΈ

sep – Custom Separator

Controls how multiple values are separated.

sep_example.py

print("2025", "12", "08", sep="-")

end – Custom Ending

By default, print() ends with a newline (\n). You can change this with the end parameter.

end_example.py

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

Note

🧠 Useful when printing multiple values on the same line.

4. Formatting Output 🎨

You can format output using three common methods:

1. f-Strings (Recommended)

fstring.py

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

2. format() Method

format_method.py

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

3. % Formatting (Older Style)

percent_format.py

print("My name is %s and I am %d years old." % ("Sathish", 25))

Note

✨ f-strings are the fastest and cleanest way to format output.

5. Escape Characters πŸ”§

Use escape sequences to print special characters.

Escape CodeDescriptionExample
\nNew Lineprint("Hello\nWorld")
\tTab Spaceprint("A\tB")
\'Single Quoteprint('It\'s Python')
\"Double Quoteprint("He said \"Hi\"")

escape_example.py

print("Hello\nWorld")
print("A\tB")

6. Printing Without Newline πŸ”„

Use end="" to print without automatically moving to the next line.

same_line.py

for i in range(5):
    print(i, end=" ")

7. Printing Raw Strings πŸ“Œ

Use r"" to print backslashes without escape behavior.

raw_string.py

print(r"C:\Users\Sathish")

8. output With File Writing (Optional) πŸ“

print() can also write to files using the file parameter.

file_output.py

with open("output.txt", "w") as f:
    print("Hello File!", file=f)

Note

πŸ“ This creates a file and writes the text into it.

9. Real-World Output Example 🎯

real_world_example.py

name = input("Enter your name: ")
age = int(input("Enter your age: "))

print(f"Hello {name}! Next year, you will be {age + 1} years old.")

Conclusion πŸŽ‰

>>β€œOutput is how your program communicates β€” mastering print() gives your code a clear voice.” πŸ”₯

You now understand all major ways of displaying output in Python. Want a tutorial on operators, expressions, conditional statements, loops, or functions? Just tell me! 😊