Skip to content

Print function in Python

Print Function in Python

Print function in Python prints any message to the output screen or any other standard text stream file . The message can be integer , string or any other object but before printing message will be converted into a string.

Syntax of print function in Python

print(objects, sep=separator, end=end, file=filename, flush=flushvalue)

Parameters of print function in Python

  • objects = Any object . We can give multiple objects to the print function separated by comma(,) . All the objects will be converted into string before printing .
  • sep = Optional ,must be a string , specify how to separate more than one object in output screen . Default is " "(a white space).
  • end = Optional , must be a string , specify what to print at the end . Default is "\n"(New line) .
  • file = Optional , must be an object with a write method . Default is sys.stdout .
  • flush = Optional , must be a boolean , specifying if the output is flushed (True) or buffered (False). Default is False .

Return type of print function in Python

It returns None .

Print function in Python Examples

Example 1: Print a single string

print("Hello World!")
Hello World!

In the above code we have given a single object in the print function .

Example 2: Print multiple string

print("Welcome","to","Coding Conception")
Welcome to Coding Conception

In the above code we have given multiple objects in the print function . We can see all the objects are separated by a single space(" ") in the output screen which is the default behavior of sep parameter .

Example 3: Changing the sep parameter

print("Welcome","to","Coding Conception",sep="***")
Welcome***to***Coding Conception

In the above code we have used *** as sep . So , we can see all the objects are separated by *** in the output screen .

Example 4: Print with default end parameter

print("Welcome")
print("Rajkumar Bhattacharya")
Welcome
Rajkumar Bhattacharya

In the above code we have used print function twice with a single object . We can see in the first line welcome is printed and in the second line Rajkumar Bhattacharya is printed . As the default value of end parameter is "\n"(new line) so after Welcome a new line is printed and then Rajkumar Bhattacharya is printed .

Example 5: Changing the end parameter

print("Welcome" , end="***")
print("Rajkumar Bhattacharya")
Welcome***Rajkumar Bhattacharya

In the above code we have customized the end parameter with *** for first print function . So, after Welcome, *** is printed and then Rajkumar Bhattacharya is printed .

Thank you for reading this Article . If You enjoy it Please Share the article . If you want to say something Please Comment .

3 thoughts on “Print function in Python”

Leave a Reply