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 Janakpur Dham, Nepal. He was born on December 23, 1994, 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. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



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

Leave a Comment