Skip to main content

Command Palette

Search for a command to run...

πŸ–¨οΈ Python print() Function

Published
β€’2 min readβ€’View as Markdown
S

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:

ParameterWhat It DoesSmall Example
dataWhat you want to printprint("Hello", 123)
sepSeparator between itemsprint("Hi", "Safia", sep="❀️")
endWhat to show after the lineprint("Loading", end="...")
fileSend output to a file instead screenprint("Hello", file=f)
flushShow output instantlyprint(".", end="", flush=True)

More from this blog

Untitled Publication

136 posts