google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 How to Use print() Output function in Python

How to Use print() Output function in Python

0

Output Function in Python

output function


The print() function prints the specified message to the output screen, or other standard output device.

The message can be a string, numeric, special character, or any other object, the work of the print() function to convert the object into a string before written to the screen. 

Syntax:

 

print(object(s), sep=separator, end=end, file=file, flush=flush)

 

How to Use Different Parameter of print():


Parameter

Description

object OR

object(s), value, Statement

Any type of object, and as many (Value & Statement) as you like. This will be converted it into string value before print on the output screen.

sep='separator'

This Field is Optional.

Use to separate the objects value, if there is more than one object. Default separator is use as ' '. (space)

end='end'

This Field is Optional.

Use to print at the end of the line or instruction.

Default is '\n' (line feed)

file

This Field is Optional.

An object with a write method. Default is sys.stdout

flush

This Field is Optional.

A Boolean value, specifying if the output is flushed (True) or buffered (False). Default is False

 

How to Use the Print Function / Output Function:

Example 1:

Print Single Object Value:-

 

print("Hello")

 

Here print have an object value “Hello”. It’s print on the output screen.

Example 2:

Print Multiple Object Value:-

 

 

print("Hello""how are you?")

 

OR

 

print("Hello""how are you?", “ How can I help You”)

 

 

Example 3:

Use of Separator “sep”

“Separator is use for the separate an object with the other object.”

 

 

print("Hello""how are you?", sep="-")

 

OR

 

print("Hello""how are you?", sep="---")

 

OR

 

print("Hello""how are you?", sep="à")

 

OR

 

print("Hello""how are you?", sep="!")

 

Output :

Hello how are you

 

Hello --- how are you?

 

Hello à how are you?

 

Hello ! how are you?

 

Example 4:

Use of end parameter

The print method is set to end on a newline by default. It means there is no need to declare “\n” at the end of the line like other language C, C++ & Java etc.

print("Life",)

print("is awesome")

 

print("Life", end= "\n")

print("is awesome")

 

Output is:

Life

is awesome

 

Life

is awesome

 

So the end option in Python is used to append any string to the end of the print statement's output.

Like:

 

print("Life", end=' ')

print("is awesome")

 

OR

print("Life", end=' @')

print("is awesome")

 

 

Here we use Space at the end of the statement.

So the Output is:

 

Life is awesome

 

Life@is awesome

 

 





Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top