Printing Statements
Printing statements
Syntax:
print expression/constant/variable
Print evaluates the expression before printing it on the monitor. Print statement outputs an entire (complete) line and then goes to next line for subsequent output (s). To print more than one item on a single line, comma (,) may be used.
Example
>>> print “Hello”
Hello
>>> print 5.5
5.5
>>> print 4+6
10
Try this on the computer and evaluate the output generated
>>>print 3.14159* 7**2
>>>print “I”, “am” + “class XI”, “student”
>>>print “I‟m”,
>>>print “class XI student”
>>>print “I‟m “, 16, “years old”
Example
print (“string to be displayed as output ” )
print (variable )
print (“String to be displayed as output ”, variable)
print (“String1 ”, variable, “String 2”, variable, “String 3” ……)
Example
>>> print (“Welcome to Python Programming”)
Welcome to Python Programming
>>> x = 5
>>> y = 6
>>> z = x + y
>>> print (z)
11
>>> print (“The sum = ”, z)
The sum = 11
>>> print (“The sum of ”, x, “ and ”, y, “ is ”, z)
The sum of 5 and 6 is 11
The print ( ) evaluates the expression before printing it on the monitor. The print () displays an entire statement which is specified within print ( ). Comma ( , ) is used as a separator in print ( ) to print more than one item.