Page 485 - ComputerScience_Class_11
P. 485

5.  Identify the Python operator that is used to check if an element is present in a sequence.
                       a.  is                                          b.  not in
                       c.  in                                          d.  is not

                   Answers
                     1.  b     2.  a     3.  b     4.  d    5.  c

                 B.  Fill in the blanks.

                    1.  An ………………… is a symbol or keyword that tells Python to perform a specific operation.
                    2.  The modulus operator (%) in Python returns the ………………… of division.
                    3.  The != operator checks if two operands are ………………… in Python.
                    4.  A ………………… operator in Python works with only one operand to perform an operation.
                    5.  A ternary operator in Python works with ………………… operands and is used to choose between two values based on a condition.

                   Answers
                     1.  operator   2.  remainder   3.  not equal   4.  unary     5.  three



                 C.  Answer the following questions:
                    1.  Why is operator precedence important in Python?
                   Ans.  Operator precedence refers to the order in which Python evaluates different operators in an expression. When an expression
                       contains more than one operator, Python follows a predefined priority rule to decide which operation should be performed first.
                        •  Operators with higher precedence are solved first and operators with lower precedence are solved later.
                        •  If two operators have the same precedence, the expression is evaluated according to associativity (usually left to right).
                    2.  State the difference between the logical operators and and or.
                   Ans.  The and operator returns True only if both conditions are true, while the or operator returns True if at least one of the
                       conditions is true. These operators are used to combine multiple conditions.
                    3.  What are Membership operators?
                   Ans.  Membership operators are used to test whether a particular value is a part of a sequence such as a list, tuple, string or set. They
                       help determine the presence or absence of an element within a collection. The result of a membership operation is always True
                       or False.
                        Python provides two membership operators:
                              Operator                                 Description
                                 in       Evaluates to True if the specified element is found in the sequence.
                                not in    Evaluates to True if the specified element is not found in the sequence.

                    4.  How does the ternary operator work in Python?
                   Ans.  A ternary operator is a type of operator that works on three operands to perform a conditional operation. It allows selecting a
                       value based on a condition in a single line, the ternary operator allows you to choose between two values based on a condition
                       using only one line of code.
                        Syntax of ternary is as follows:
                       value_if_true if condition else value_if_false
                    5.  How does the is operator work in Python and how is it different from the == operator?
                   Ans.  The is operator checks whether two variables point to the same object in memory, while the == operator checks if two variables
                       have the same value. is compares memory addresses, while == compares values.
                    6.  What is an expression?
                   Ans.  An expression in Python is a combination of values (constants), variables, operators and sometimes function calls that Python
                       evaluates to produce a single result. In simple terms, an expression is anything that gives a value when it is executed.
                        Expressions can perform calculations, compare values or even call functions, but their main purpose is to return a result. The
                       result of an expression can be a number, string, Boolean value (True/False) or any other data type.
                        For example,
                        1.  10 + 2 (evaluates to 12)
                        2.  "Hello " + "World" (evaluates to “Hello World”)



                                                                                           Operators and Expressions  483
   480   481   482   483   484   485   486   487   488   489   490