Output through print() statement
The print( ) function of python is a
way to send output to standard output device, which is normally a monitor.
The
simplified syntax3 to use print( ) function is as follows –
print(“you can print anything by
this function”)
Let us consider some simple examples
–
print(“Hello”) # a string
print(175) # a number
print(3.14) # a float or value of pi
Let us consider some examples with
there outputs –
Example 1 –
print(“my name is jack”)
output is –
my name is jack
example 2 –
print(“product of 2 and 3 is ”,2*3)
output is –
product of 2 and 3 is
6
example 3 –
a=25
print(“the half of the ,a, is”,a/2)
output is –
the half of the 25 is 12.5
Features of print statement
The print statement has a number of
features:
1 – it auto converts the item to
strings i.e., if you are printing a numeric value then the print statement will
convert the numeric value to the strings and print it ; for numeric values
first the print statement will evaluate the values and then converts the result
to the strings
2 – the print statement will insert
the spaces (gapes) automatically because of the default value of the sep
argument is spaces (‘ ’). The sep argument shows the separator character. The
print statement will automatically add the sep statement between the items or
objects which is being printed in the next line. If we did not leave the space
then by default the sep character will automatically leave the spaces in
between the items or objects.
Example –
print(“my”,”name”,”is”,”jack”)
output is –
my name is jack
3 – it adds a new line character at
the end of the line unless until you give your own end command.
The new line character is
represented by the - \n
Since the new line character will
leave one line after the one statement in the python shell.
Output through print() statement
Reviewed by Learn Python
on
November 04, 2019
Rating:
No comments: