Page 173 - AI_Ver_3.0_class_11
P. 173

result_add = a + b
                     print("Addition:", result_add)

                     # Subtraction
                     result_sub = a - b
                     print("Subtraction:", result_sub)
                     Output:

                     Addition: 15
                     Subtraction: 5


                         Character Set

                 In Python, a character set refers to a collection of characters, typically defined by a specific encoding scheme, such as
                 ASCII (American Standard Code for Information Interchange) or Unicode. Each character in a character set is represented
                 by a unique code point.
                 A programming language’s character set refers to the permissible  characters recognised by that language.  When
                 discussing the Python programming language specifically, its character set encompasses all valid characters allowed for
                 scripting. These include:
                  • •  Letters: Both uppercase (A-Z) and lowercase (a-z) letters.
                  • •  Digits: All numerical digits from 0 to 9.
                  • •    Special Symbols: Python accommodates various special symbols such as single quotes ('...'), double ("...“), semicolons
                     (;), colons (:), exclamation marks(!), tildes (~), at symbols(@), hash signs (#), dollar signs ($), percentage signs (%),
                     caret sign (^), backticks (`), ampersands (&), asterisks (*), parentheses (), underscores(_), plus signs(+), hyphens(-),
                     equal signs(=), curly braces {}, square brackets [], and backslashes(\).
                  • •    Whitespace  characters: Python recognises  whitespace characters  including tab spaces, blank spaces, newline
                     characters, and carriage return characters.
                  • •    Others: Python supports the entirety of ASCII and Unicode characters, comprising the complete Python character
                     set.


                         Tokens


                 A token is the smallest unit of a program that has a meaning. Tokens in Python are fundamental elements of the language’s
                 syntax. They represent the building blocks of Python code, consisting of keywords, identifiers, literals, operators, and
                 punctuations. Understanding tokens is essential for comprehending Python’s lexical structure (basic syntax and set of
                 rules defining how Python programs are written) and parsing rules (guidelines used by a parser to analyse the structure
                 of code).
                 Python code is first divided into tokens during the lexical analysis phase of the interpretation process. These tokens are
                 then used by the parser to construct the abstract syntax tree (AST a tree representation of Python code that is used for
                 code analysis and manipulation), which is further processed to execute the code.

                                                                  Tokens





                            Keywords          Identifiers         Literals         Operators        Punctuators



                                                                                         Python Programming     171
   168   169   170   171   172   173   174   175   176   177   178