Chapter 5 Introduction To Python
Chapter 5 Introduction To Python
Syntax :
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(“The total is “, total ,”and the average is “,ave)
Output:
Enter Number 1: 200
Enter Number 2: 50
The sum = 250
The difference = 150
The remainder is =0
Velammal Matric. Thiruppuvanam
The input() function
Example 4: (Alternative method)
x,y=int (input("Enter Number 1 :")),int(input("Enter
Number 2:"))
print ("X = ",x," Y = ",y)
Output:
Enter Number 1 :30
Enter Number 2:50
X = 30 Y = 50
Velammal Matric. Thiruppuvanam
Comments in Python
In Python, comments begin with hash symbol (#).
Examples :
# Fibonacci program - Single line comment
# Fibonacci program work under the category of
dynamic programming structure #
- Multiline comment
Indentation
Example 2:
i=10
while (i<=15):
print(i,end='\t‘)
i=i+1
Velammal Matric. Thiruppuvanam
Tokens
Python breaks each logical line into a sequence of
elementary lexical components is know as Tokens
Whitespace separation is necessary between tokens,
identifiers or keywords.
2) Keywords,
3) Operators,
5) Literals.
+=, -=, *=, /=, %=, **= and //= are known as Compound
Operators
SYNTAX