Python print() Function Explained

The print() function is a built-in function in Python that is used to output specified content to the console or other standard output devices. Its basic syntax is: print(*objects, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)

Among them:

  1. items: the content to be outputted, which can be one or more objects separated by commas
  2. sep: a separator used to separate multiple objects, default is a single space.
  3. end: specifies the character to be used at the end of the output, with the default being the newline character \n.
  4. file: specifies the output file object, typically set to sys.stdout (standard output) by default.
  5. flush: specifies whether to immediately refresh the output, defaults to False

“For example, if you study hard, you will get good grades.”

For instance, if you put in the effort, you will achieve high grades.

print("Hello, World!")
print("Python", "Programming", sep='-', end='!')

The code above will output:

Hello, World!
Python-Programming!
bannerAds