How to use Print function in Python

How to execute the print() function in Python

The print() function prints the specified message to the screen or another standard output device. The message can be a string or any other object, the object will be converted into a string before written to the screen.

Syntax:-

print(object(s), separator=separator, end=end, file=file, flush=flush)

Example:

print(object(s), sep=' ', end='\n', file=sys, flush=False)

Parameters:

  • object(s) – Object(s) to be printed on the screen.
  • sep – object(s) will be printed separately with the separator between and the default value is ‘ ‘
  • end – It will break the line into the next line. By default, it is set to ‘\n’.
  • file – An object with a write method. Default: sys.stdout
  • flush – A Boolean, specifying if the output is flushed (True) or buffered (False). Default: False

Example to use of Print Function

  • Printing single object onto the screen:
print("hello world")
  • Printing two or more objects onto the screen.
print("line A \nline B")
print("line a\n line b\n line c")
  • Print string into in single ‘abc’ and the double court “abc” in a sentence.
print('line "a" \nline "b"')
  • Print single ‘/’ or more slice ‘//’ in a sentence.
print("/\ /\\ //\ ")
  • Input the value using a separator (“,”)
name,age=input("enter value a and b:").split(",")
age=int(age)
print(name,'\n',age)

Output:

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
enter value a and b:pramod,24
pramod 
 24

Recommended Post:

Get Salesforce Answers

Pramod Kumar Yadav is from Janakpurdham, Nepal. He was born on December 23, 1996, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India.He is director of Appan Bazaar Pvt.Ltd., as teacher in Tridev Eng. School , and an Educational Consultant, and he is currently working as a developer and Digital Marketer.



0 thoughts on “How to use Print function in Python”

  1. Retour aux sources avec notre gamme de produits naturels et bio. Huiles essentielles, phytotherapie et complements alimentaires de qualite. Des solutions douces pour prendre soin de votre corps au quotidien. Commandez vos allies bien-etre en toute simplicite.medex

    Reply

Leave a Comment