Page 182 - AI Ver 3.0 Class 11
P. 182

Program 11: To demonstrate the use of identity operators

                   # Uses of Identity Operators

                   # is
                   x = [1, 2, 3]

                   y = [1, 2, 3]
                   print("Is x the same object as y?", x is y)

                   # is not
                   print("Is x not the same object as y?", x is not y)
              Output:
                  Is x the same object as y? False
                  Is x not the same object as y? True


              Operator Precedence
              The precedence of operators determines the order in which the operators are executed. The operator precedence in
              Python is listed in the following table. The highest precedence is at the top.

                                        Operator                                  Name
                                            ()                  Parentheses
                                            **                  Exponent
                                        *, /, %, //             Multiplication, Division, Modulus, Floor Division
                                           +, –                 Addition, Subtraction
                                   ==, !=, >, <, >=, <=         Comparison
                               =, +=, -=, *=, /=, %=, **=, //=   Assignment
                                       and, or, not             Logical


              Punctuators
              Punctuators in Python are special characters used for various purposes such as accessing attributes, separating elements,
              specifying syntax, and more. Some common punctuators in Python are as follows:

               • •  Period (.): Used for accessing attributes and methods of objects.
               • •  Comma (,): Separates elements in tuples, lists, function arguments, and dictionary key-value pairs.
               • •    Colon (:): Used in dictionaries to separate keys from values, in slices, and in control structures like loops and conditionals.
                  To define the beginning of an indented code block.
               • •  Semicolon (;): Can be used to separate statements on the same line.

               • •    Question Mark (?): In some contexts, such as libraries like NumPy or IPython, it’s used for querying documentation
                  or help.

               • •  Exclamation Mark (!): Often used in Python shells like IPython or Jupyter notebooks to execute shell commands.
               • •  Parentheses (()) and Brackets ([]): Used for grouping expressions, function calls, and indexing/slicing sequences.
               • •  Quotation Marks (' and "): Used to denote string literals.
               • •  Curly Braces ({}): Used to denote sets and dictionaries, and in formatting strings.

               • •  Asterisk (*): Used for multiplication, exponentiation, and in unpacking iterables.
               • •  Forward Slash (/): Used for division.
               • •  Backslash (\): Used for line continuation or as an escape character in strings.


                    180     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   177   178   179   180   181   182   183   184   185   186   187