Print () function in Python
The print () function in Python works to display the screen magic when the program executes.
Full syntax of print ():
print(*objects, sep=' ', end='n', file=sys.stdout, flush=False)
The parameter of the print () function:
objects
: objects are printed, there may be many objects. Will be converted into a string before displaying to the screen.sep
: how to separate objects, the default value is a spaceend
: the final value is printed to the screen.file
: By default the print function will write the content to the sys.stdout file .flush
: The default value is False.
Note : sep, end, file and flush are all keyword parameters. If you want to use the sep parameter, you must use this:
print (* objects, sep = 'separator')
Can not use; Out of order; It disfunction:
print (* objects, 'separator')
Example 1: The way print () works in Python
print("Học Python rất thú vị.")
a = 5
# 2 object
print("a =", a)
b = a
# 3 object
print('a =', a, '= b')
Run the program, the result is:
Học Python rất thú vị.
a = 5
a = 5 = b
In the three statements in the above example, only the object parameter is used in the statements.
Example 2: print () with separator and end parameters
a = 5
print("a =", a, sep='00000', end='nnn')
print("a =", a, sep='0', end='')
Run the program, the result is:
a =000005
a =05
See also: Built-in Python functions
4 ★ | 1 Vote
You should read it
May be interested
- The function dir () in Pythonthe dir () function in python returns a list of valid properties of the object. quantrimang will learn more about this function content through the article. invites you to read the track.
- The function set () in Pythonin this article, tipsmake.com will learn with you about set (), syntax, parameters and specific examples. invites you to read the track.
- Help () function in Pythonthe built-in help () function in python is used to display documents and invoke the help system of modules, functions, classes, keywords ...
- Sum () function in Pythonthe built-in function sum () in python returns the sum of all numbers in iterable.
- The slice () function in Pythonthe slice () function in python returns a slice object that helps you determine how to cut an existing string.
- The chr () function in Pythonin python, the chr () function returns a character (a string) from an integer that represents the unicode of the returned character.
- The iter () function in Pythoncontinuing with the topic of python's built-in functions, the article will introduce you to the iter () function with the syntax, usage as well as specific examples. invites you to read the track.
- The pow () function in Pythonthe pow () function built into python returns the value of x with the power of y (xy). if there is a third parameter, the function returns x to the power y, the module z.
- The reversed () function in Pythonthe reversed () function is one of the built-in functions in python, used to reverse the original string returning the iterator.
- Built-in Python functionsin the previous article, you learned that python has a basic function type, one is a built-in function, two are user-defined functions. today, we will learn about a list of python's built-in functions.