Monday, 27 May 2013

Python learning: Using arithmetic Operators

Arithmetic Operators

Addition
a = 5
b = 7
c = a+b
print(c)
12

Subtraction
a = 5
b = 7
c = a-b
print(c)
-2

Multiplication
a = 5
b = 7
c = a*b
print(35)
35

Division
a = 5
b = 7
c = a/b
print(c)
0.7142857142857143

Now see how to use operators in strings

>>>a = "Good"
>>>b = "morning"  //use double quotes " " otherwise you will get error.
>>>c = a+b
>>>print(c)
>>>Goodmorning

>>>a = hello
>>>b = a*3
>>>print(b)
>>>hellohellohello





No comments:

Post a Comment