DEV Community

Cover image for print function in python
Aswin Barath
Aswin Barath

Posted on • Edited on

2 3 1 1 1

print function in python

print() function and input() function makes the program more interactive with the user.

Although, there are some extra things we can do with print() which makes the output formattable.

Functionalities of print() function

  • Let's start with the syntax: print(object(s), sep=separator, end=end, file=file, flush=flush)
  • Fact: In python, all data types are implemented as an object.
  • object(s): Will accepts any number of objects, which will be converted into a string before printed. We can pass it in two way:
  • Concatenated: Alt Text
  • Comma seperated: Alt Text Output:
Enter any number: 2021
year:2021
Enter fullscreen mode Exit fullscreen mode
  • sep='separator': This is Optional. Used to specify how to separate the objects, if there is more than one. Default is ' ' (space). Alt Text Output:
Enter any number: 2021
year:   2021
Enter fullscreen mode Exit fullscreen mode
  • end='end': This is Optional. Used to specify what to print at the end. Default is '\n' (new line). Alt Text Output:
Enter any number: 2021
year: 2021  month: Jan
Enter fullscreen mode Exit fullscreen mode
  • file: This is Optional. Default is sys.stdout. Used to specify the name of the file to write the output. If the file doesn't exist, it will create a new file. Alt Text Output (in 'Greetings.txt' file):
!!! Wish you a happy new year   !!!
Enjoy the year--->2021---> and the month --->January
Enter fullscreen mode Exit fullscreen mode

Best Resources

Who Am I?

I’m Aswin Barath, a Software Engineering Nerd who loves building Web Applications, now sharing my knowledge through Blogging during the busy time of my freelancing work life. Here’s the link to all of my socials categorized by platforms under one place: https://linktr.ee/AswinBarath

Thank you so much for reading my blog🙂.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay