Page 470 - ComputerScience_Class_11
P. 470

Program 3: To display the output of Ternary operator.

                   Program 3.py
                File  Edit  Format   Run   Options   Window    Help

                # Assign values to two variables
                a = 10
                b = 20


                # Use ternary operator to find the maximum value
                max_value = a if a > b else b


                # Print the result
                print("Maximum value =", max_value)




                  Output

                Maximum value = 20




                  12.2 TYPES OF OPERATOR
              In Python, operators are special symbols or keywords used to perform operations on values or variables. They can be
              grouped based on the type of operation they perform. This grouping helps in understanding their purpose and usage
              more easily.
              The operators in Python can also be grouped by the type of operation they do, as enumerated below:

              •  Arithmetic operators
              •  Comparison Operators
              •  Assignment operators
              •  Logical Operators
              •  Identity Operators
              •  Membership Operators

              •  Bitwise Operators

              12.2.1 Arithmetic operators
              Arithmetic operators are used to perform mathematical operations, including addition, subtraction, multiplication,
              division, modulus, exponentiation and floor division.
              The following table shows the arithmetic operators in Python along with their description:

                Operator                                           Description
                     +       Adds two operands or unary plus.
                     -       Subtracts right operand from left operand or unary minus.
                     *       Multiplies two operands.
                     /       Divides left operand by right operand.
                    %        Returns the remainder of the division.
                    //       Performs floor division (a division that results in whole number adjusted to the left in the number line).
                    **       Performs exponentiation (left operand raised to the power of right operand).



                  468  Touchpad Computer Science (Ver. 3.0)-XI
   465   466   467   468   469   470   471   472   473   474   475