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
- Sum () function in Pythonthe built-in function sum () in python returns the sum of all numbers in iterable.
- __Import __ () function in Python__import __ () is an advanced function called by the import statement in python
- The function hasattr () in Pythonthe hasattr () function in python is used to check if the input object has the property you want to find.
- Filter () function in Pythonhow is the filter () function syntax, what parameters and how does it work? invites you to read the track.
- Int () function in Pythonthe int () function in python returns an integer object from any number or string.
- Wool () function in Pythonhow is the syntax of len () function, what parameters do it have and how is it used? invites you to read the track.