Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python print() Function

Python print() Function

Python3 Built-in Functions Python3 built-in function


Description

print() method is used to print output, and is the most commonly used function.

The flush keyword argument was added in Python 3.3.

print is a function in Python 3.x, but it is not a function in Python 2.x—it is merely a keyword.

Syntax

The following is the syntax of the print() method:


print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

Parameters

Return Value

none.


Example

The following shows an example of using the print function:

Tested under Python3

print

(

1

)

1

print

(

"

Hello World

"

)

Hello

World

a

=

1

b

=

'

runoob

'

print

(

a

,

b

)

1

runoob

print

(

"

aaa

"

"

bbb

"

)

aaabbb

print

(

"

aaa

"

,

"

bbb

"

)

aaa

bbb

print

(

"

www

"

,

"

runoob

"

,

"

com

"

,

sep

=

"

.

"

)

Set the separator

www

.

runoob

.

com

Use the flush parameter to create a Loading effect:

Example

import

time

print

(

"---RUNOOB EXAMPLE : Loading effect---"

)

print

(

"Loading"

,

end

=

""

)

for

i

in

range

(

20

)

:

   

print

(

"."

,

end

=

''

,

flush

=

True

)

   

time

.

sleep

(

0.5

)

The effect is shown in the figure below:

For more information, refer to:Python3 print Function Usage Summary

Python3 Built-in Functions Python3 built-in function