Python is a general-purpose, high-level programming language. It was designed with an emphasis on code readability, and its syntax allows programmers to express their concepts in fewer lines of code, and these codes are known as scripts. These scripts contain character sets, tokens, and identifiers. In this article, we will learn about these character sets, tokens, and identifiers. Show Character setA character set is a set of valid characters acceptable by a programming language in scripting. In this case, we are talking about the Python programming language. So, the Python character set is a valid set of characters recognized by the Python language. These are the characters we can use during writing a script in Python. Python supports all ASCII / Unicode characters that include:
TokensA token is the smallest individual unit in a python program. All statements and instructions in a program are built with tokens. The various tokens in python are : 1. Keywords: Keywords are words that have some special meaning or significance in a programming language. They can’t be used as variable names, function names, or any other random purpose. They are used for their special features. In Python we have 33 keywords some of them are: try, False, True, class, break, continue, and, as, assert, while, for, in, raise, except, or, not, if, elif, print, import, etc. Python3
Output: 1 2 3 4 5 6 2. Identifiers: Identifiers are the names given to any variable, function, class, list, methods, etc. for their identification. Python is a case-sensitive language and it has some rules and regulations to name an identifier. Here are some rules to name an identifier:-
Python3
Output: Hello Geeks 3. Literals or Values: Literals are the fixed values or data items used in a source code. Python supports different types of literals such as: (i) String Literals: The text written in single, double, or triple quotes represents the string literals in Python. For example: “Computer Science”, ‘sam’, etc. We can also use triple quotes to write multi-line strings. Python3
Output Hello Geeks Geeks for Geeks is a learning platform (ii) Character Literals: Character literal is also a string literal type in which the character is enclosed in single or double-quotes. Python3
Output: G W (iii) Numeric Literals: These are the literals written in form of numbers. Python supports the following numerical literals:
Python3
(iv) Boolean Literals: Boolean literals have only two values in Python. These are True and False. Python3
(v) Special Literals: Python has a special literal ‘None’. It is used to denote nothing, no values, or the absence of value. Python3(vi) Literals Collections: Literals collections in python includes list, tuple, dictionary, and sets.
Python3
Output [23, 'geek', 1.2, 'data'] (1, 2, 3, 'hello') {1: 'one', 2: 'two', 3: 'three'} {1, 2, 3, 4} 4. Operators: These are the tokens responsible to perform an operation in an expression. The variables on which operation is applied are called operands. Operators can be unary or binary. Unary operators are the ones acting on a single operand like complement operator, etc. While binary operators need two operands to operate. Python3
5. Punctuators: These are the symbols that used in Python to organize the structures, statements, and expressions. Some of the Punctuators are: [ ] { } ( ) @ -= += *= //= **== = , etc. |