Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
print

How to execute the print() function in Python

Educative Answers Team

The print() function in Python converts the given object(s) to a string first before printing it (them) to the screen.

svg viewer
Sample Flow

Syntax

The syntax of print() function is:

 print(Object(s), sep=‘ ‘, end=‘\n’, file=sys.stdout, flush=False) 

Parameters

  • Object(s) - Object(s) to be printed on the screen.

  • sep - object(s) are printed separately with the separator in between, and the default value is ‘ ’. (optional)

  • end - end is printed at last, and the default value is ‘/n’.(optional)

  • file - Object with a write(string) function, and the default value is sys.stdout. (optional)

  • flush - If True, the stream is flushed otherwise buffered and the default value is False. (optional)

print() function in Python returns None.

Examples

  • Printing one object onto the screen:
print("Educative") 
  • Printing more than one object onto the screen:
print("Educative", "provides interactive courses.")
  • Printing two objects with a separator:
print("Educative", "Provides interective courses.", sep=": ")
  • Printing one object with end parameter:
print("Educative", end=' !!')
  • Printing one object into the file:
# Creating output file
with open('output/output.txt', 'w') as f:
    print('Educative', file=f) # Printing Educative in output.txt file

RELATED TAGS

python
print
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring