Operator are the special symbols which we can use for arithmetic and logical expression. There are many types of operator based on their use like arithmetic operator(+.-./,*), comparative operator and so on.
>>> a=10
>>> b=20
>>> a+b
30 # Thus + is the arithmetic operator
Similarly for comparative operator, there are equal to(==), less than or equal to(<=), greater than or equal to(>=), not equal to (!=), less than (<) and greater than(>) operator.
>>> 1<5
True
>>> 1>5
False
A simple program to calculate the months and days when we give the input as days.
days = int(input(” Enter the number of days “
months = days / 30
remaining_days = days % 30
print(” %d months and %d days ” % (months, remaining_days)
When we give the input as 135, this will show the input as ” 4 months and 15 days “
Expression
>>> a = 5
>>> b = 10
>>> c = 15
>>>x= a + (b*c)
>>> print(x)
155
In the program the expression which is enclosed with the () parentheses will be given first priority and gets executed. And then the value is added to the expression. Similarly for different variable there is different priority in which it is executed.
Type Conversion
>>> a = ” Chandru “
>>> int(a)
274
Thus we want to change the type of variable manually. The second line converts the string value and displays the equivalent value which is converted to the integer type. Similarly we can convert float to string or string to float and any other variable.