Page 69 - TP_Prime_V2.2_Class7
P. 69

06
                                                               MORE ON

                                                                 PYTHON









                                                                            Learning Objectives
                                                                            •  Operators in Python                          MORE ON PYTHON
                                                                            •  Operator Precedence
                                                                            •  Conditional Statements





                                 Yesterday, when I was doing my Maths home work, I used Calculator to solve               67

                                arithmetic problems. Can we create programs in Python which help us to do
                                arithmetic problems?

                                Yes, we use operators in Python to solve mathematical problems. Let's learn

                                about them.

                 In the previous class, we learnt how to initialise a variable. We also learnt how to declare
                 the data type and accept input in Python. Let us take a step ahead and learn to use Python

                 for arithmetic and logical programming.

                  Operators in Python

                 Operators  are  symbols  that  perform  operation  on  operands  to  provide  result  that  we

                 expect. These can be arithmetic or logical as needed. Any expression needs both operators
                 and operands for a successful operation.

                 For example, X+Y=Z
                 In the above example, = and + are the operators and X, Y and Z  are the operands.

                  Arithmetic Operators

                 As  the  name  suggests,  arithmetic  operators  are  used  to  perform  basic  mathematical

                 operations or calculations. These are (+) addition, (–) subtraction, (*) multiplication, (/)
                 division, etc. Arithmetic operators can be divided into two categories.

                 Unary  Operators

                 Unary operators require a single operand and are commonly used to change a value to its
                 negative form or to indicate that it is positive. For example, A=-20 | B=–40
   64   65   66   67   68   69   70   71   72   73   74