Page 174 - AI_Ver_3.0_class_11
P. 174

Keywords
              Keywords are predefined and reserved words in Python, which have special meanings and purposes. They cannot be
              used as identifiers or variable names. These keywords are part of Python’s syntax and are used to define control flow,
              declare functions and classes, handle exceptions, etc.
              Following table shows the keywords used in Python:
                                   and          as           assert       async        await
                                   break        class        continue     def          del
                                   elif         else         except       False        finally
                                   for          from         global       if           import
                                   in           is           lambda       None         nonlocal
                                   not          or           pass         raise        return
                                   True         try          while        with         yield


              Identifiers
              Identifiers are the names used to identify variables, functions, classes, modules, and other objects in Python. They act as
              labels for these elements, allowing you to refer to them in your code. Identifiers follow certain rules and conventions:
               • •  Must begin with a letter (a-z, A-Z) or an underscore (_).
               • •  Subsequent characters can be letters, digits (0-9), or underscores.
               • •  Case-sensitive (myVar is different from myvar).

               • •  Cannot be a Python keyword (reserved words).
               • •  No special characters such as !, @, #, $, %, etc., are allowed within identifiers.
               • •  Blank spaces within an identifier are disallowed.
              For example:

                   my_variable
                   calculate_sum
                   MyClass
              Some conventions that can be used while specifying identifiers for more clarity are as follows:

               • •  Use descriptive names that convey the purpose of the variable, function, etc.
               • •    Follow the snake_case convention for variable names and function names. This means using all lowercase letters
                  with words separated by underscores. For example: my_variable, calculate_sum.

               • •    Follow the PascalCase convention for class names. This means capitalising the first letter of each word, without
                  underscores. For example: MyClass, BankAccount.
               • •  Use all uppercase letters with underscores to denote constants. For example: MAX_SIZE, PI.


              Literals
              Literals in Python represent fixed values that are used directly in the code. They can be of several types:

               • •  Numeric literals: Represented as integers, floating-point numbers, or complex numbers. Examples: 42, 3.14, 1 + 2j.
               • •    String  literals: Represented as sequences of characters enclosed in single, double, or triple quotes. Examples:
                  'hello', "world", '''multiline string'''.

               • •  Boolean literals: Represented as True or False.
               • •  None literal: Represented as None that indicates the absence of a value.

              Operators
              In Python, operators can be defined as special symbols which perform arithmetic and logical computation. The values
              which the operators use to get the output are called operands.

                    172     Touchpad Artificial Intelligence (Ver. 3.0)-XI
   169   170   171   172   173   174   175   176   177   178   179