π¨οΈ Python print() Function
Hi! My name is Safia Khatoon. I am complete my Bachelors in Technology from RTC Institute Of Technology. My specialisation in Computer Science and Engineering.I love contributing to Open Source with the help of the skills I gain.
Also, I'm working on my YouTube Channel as well where I teach about DevOps tools and make technical content. You can have a look at it through my profile.
Feel free to reach out to me! I'd be happy to connect with you.
πΉ 1. data / objects β What You Want to Print
These are the items you put inside print()
π Example:
print("Safia", 2025)
π¨οΈ Output:
Safia 2025
That means: strings, numbers, variables β all are data objects.
πΉ 2. sep (separator) β What Comes Between Items
By default, Python puts a space between each item.
π Example 1:
print("Code", "With", "Safia")
π¨οΈ Output:
Code With Safia
π Example 2: sep="π₯"
print("Code", "With", "Safia", sep="π₯")
π¨οΈ Output:
Codeπ₯Withπ₯Safia
π Example 3: Use / as separator (like date format)
print("20", "04", "2025", sep="/")
π¨οΈ Output:
20/04/2025
πΉ 3. end β What Comes After the Line
By default, Python adds a new line (\n) after each print()
π Example 1:
print("Hello", end=" ")
print("World!")
π¨οΈ Output:
Hello World!
π Example 2:
print("Loading", end="...")
print("Done")
π¨οΈ Output:
Loading...Done
πΉ 4. file β Send Output to a File Instead of Screen
By default, print() shows output on the screen.
But you can also write to a file!
π Example:
f = open("output.txt", "w")
print("dev_Safia is coder!", file=f)
f.close()
π― This will create a file named output.txt
Inside it, youβll see:
dev_Safia is coder!
πΉ 5. flush β Force Output to Appear Immediately
Useful in real-time applications like progress bars, loading animations, etc.
By default, flush=False
π Example:
f = open("meri_file.txt", "w")
print("dev_Safia is coder!", file=f,flush=true)
f.close()
π¨οΈ Output:
dev_Safia is coder!
π― Final Quick Recap:
| Parameter | What It Does | Small Example |
data | What you want to print | print("Hello", 123) |
sep | Separator between items | print("Hi", "Safia", sep="β€οΈ") |
end | What to show after the line | print("Loading", end="...") |
file | Send output to a file instead screen | print("Hello", file=f) |
flush | Show output instantly | print(".", end="", flush=True) |