0% found this document useful (0 votes)
11 views2 pages

Print Syntaxes

Uploaded by

raviyallampati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Print Syntaxes

Uploaded by

raviyallampati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

===============================================================

Display the Result of Python program


===============================================================
=>To display the Result of Python program , we use a pre-defined function called
print().
=>print() is pre-defined function used for displying the result of Python Program
on the console.
=>print() can be used with the following syntaxes for displying the result of
Python Program.
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
Syntax-1: print(Val1)
OR
print(Val1,Val2,.....,Val-n)
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
=>Here Val1,Val2,...Val-n Represents Values / Variable Values
-------------------
Examples
-------------------
>>> a=10
>>> print(a)-----------10
>>> a=10
>>> b=20
>>> c=a+b
>>> print(a,b,c)--------10 20 30
>>> print(100,200,300)-----100 200 300
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
Syntax-2: print(msg1)
OR
print(Msg1,Msg2,.....,Msg-n)
OR
print(Msg1+Msg2+.....+Msg-n) # here + performing Concating the Str
Values
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
=>Here msg1,msg2,....msg-n are called Strings
=>This Syntax is used for Displaying String Messages on the console.
---------------------
Examples
---------------------
>>> print("Hello Python Students")--------------Hello Python Students
>>> print("Hello",'Python','''Students''')--------Hello Python Students
>>> print("Hello"+"Python"+"Prog")-----------HelloPythonProg
>>> print("Hello"+" Python"+" Prog")---------Hello Python Prog
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
Syntax-3: print(Messages cum Values)
OR
print(Values cum messages)
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
=>This Syntax gives Messages cum Values OR Values cum messages
----------------
Examples
---------------
>>> a=10
>>> print("Val of a=",a)---------Val of a= 10
>>> print(a,"is the val of a")---10 is the val of a
----------
>>> a=10
>>> b=20
>>> c=a+b
>>> print("sum=",c)---------sum= 30
>>> print(c,"is the sum")---30 is the sum
--------------------
>>> a=10
>>> b=20
>>> c=a+b
>>> print("sum of",a,"and",b,"=",c)------sum of 10 and 20 = 30
---------------------
>>> a=10
>>> b=20
>>> c=30
>>> d=a+b+c
>>> print("Sum of",a,",",b,"and",c,"=",d)-----Sum of 10 , 20 and 30 = 60
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
Syntax-4: print(Messages cum Values with format() )
OR
print(Values cum messages with format() )
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
Examples:
------------------
>>> a=10
>>> print("Val of a={}".format(a))------------Val of a=10
>>> print("{} is the val of a".format(a))----10 is the val of a
----------------------------
>>> a=10
>>> b=20
>>> c=a+b
>>> print("sum of {} and {}={}".format(a,b,c))----sum of 10 and 20=30
----------------------------------
>>> print("sum({},{})={}".format(a,b,c))-----sum(10,20)=30
>>> a=10
>>> b=20
>>> c=30
>>> d=a+b+c
>>> print("sum of {},{} and {}={}".format(a,b,c,d))-----sum of 10,20 and 30=60

You might also like