Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 137 - CodePilot V5.0 C6
P. 137

    KEYWORDS AND IDENTIFIERS

                     In Python, keywords and identifiers are two important concepts that define the structure and
                     naming conventions of a program.

                     KEYWORDS

                     Keywords are  reserved words with special
                     meanings in Python, used for tasks like control     Python has 35 reserved keywords that cannot
                     flow (if, for, while), functions (def) and classes   be used as variable names.
                     (class). They cannot  be used  as variable
                     names. Here is a list of Python keywords:

                     False            None             True             and              as              assert
                     async            await            break            class            continue        def
                     del              elif             else             except           finally         for
                     from             global           if               import           in              is
                     lambda           nonlocal         not              or               pass            raise
                     return           try              while            with             yield
                     You cannot use keywords as variable names. For example, you cannot name a variable ‘if’ or ‘for’.

                     IDENTIFIERS

                     An identifier is a name used to uniquely identify a variable, function, class or object in Python. It
                     represents the values you store, like numbers or text.

                     Examples of Identifiers:

                         Variable identifiers: age, score, temperature

                         Function identifiers: print_message(), calculate_sum()
                         Class identifiers: Person, Student

                            VARIABLES IN PYTHON

                     In  Python,  variables store values that  can be  accessed  or changed  later. Their names  are
                     identifiers and you don’t need to specify their type because Python is dynamically typed.

                     RULES FOR NAMING VARIABLES

                     When creating variable names, make sure to follow these rules:
                         Variable names can contain letters (a-z, A-Z), digits (0-9) and underscores (_).

                         Variable names must begin with a letter or an underscore (_), but not a number.
                         Variable names are case-sensitive, so ‘age’ and ‘Age’ are considered two different variables.

                         Variable names cannot use Python keywords (such as if, else, for) as variable names.
                         Variable names cannot contain spaces.

                                                                                                                      135
                                                                                                  Python–Start to Code

| 132 133 134 135 136 137 138 139 140 141 142 |