Character set of Python:
Character set of Python basically defines the set of characters in Python that is used in Python programming language.
Alphabets English (A-Z, a-z)
Digits (0-9)
Special characters (=, -, *, /, (), [], _, =, "", '', >, <)
Unicode Characters
Python supports two encoding characters:
ASCII Code :
➡️ ASCII codes stand for American Standard Code for Information Interchange.
➡️ ASCII supports alphabets only and does not support other languages.
➡️ ASCII supports 256 characters.
Unicode :
➡️ Unicode stands for universal code.
➡️It supports all languages, e.g., Hindi, Urdu, Tamil, English, and emojis.
➡️ Unicode supports 1,55,063 characters.
What is Encoding?
Encoding is a process of converting a character into a number.
What is Decoding?
Decoding is a process of converting a number into a character.
Tokens Of Python:
Python tokens are the smallest units of Python that help you write programs that Python can understand. Without tokens, we cannot write the program.
Types of Tokens:
Keywords :
Keywords are reserved words in Python that you cannot change. They are predefined words.
There are 35 keyword
Soft Keywords : 4
What is the keyword list?
Python provides a predefined library called the keyword list.
Note: Python is a case-sensitive language, so there is a difference between uppercase and lowercase.
Identifiers :
Identifiers are basically user-defined words. They are names of variables, functions, classes, etc.
Rules:
➡️ Only these are allowed: Alphabet (a-z, A-Z), digits (0-9), underscore (_)
➡️ You cannot start with a number.
➡️ You cannot use keyword names.
➡️ There should not be any space.
Identifier can be define in upper case or lowercase
The length of an identifier can be unlimited, but you shouldn't use long names because they are complex to call.
How to verify a given word is keyword or identifier
import keyword
keyword.iskeyword('keyword_name')
What is the difference between keywords and identifiers.
Keywords :
pre-defined word
it performs specific operations
understood by Python translator
e.g., while, if, in, pass
identifiers:
it's not a pre-defined word
it basically identifies programming elements
understood by Python developers
e.g., safia, ram, age
What is the difference between a keyword and a soft keyword.
Keywords cannot be used as identifiers, while soft keywords can be used as identifiers.
Literals and Datatypes:
Literals:
Literals are fixed values or constant values that never change. There are two types of literals:
numeric literals
non-numeric literals
Datatypes:
📌 Every value we store in Python has a type.
📌 It tells us what kind of data a variable is storing.
📌 For example: Numbers, Text, True/False, List, etc.
Python datatypes are classified into 2 categories:
scalar datatypes :
➡️ Scalar datatypes are those datatypes that store one value at a time.
➡️ it is used to store a single value at a time.
➡️ Example:
int, float, complex, boolean, NoneType
collection datatypes :
➡️ Collection datatypes are those datatypes that store more than one value at a time.
Collection datatypes are classified into 3 categories :
1. sequence : list, tuple, string, range, bytes, bytearray
2. sets : set, Frozen set
3. mappings : Dictionary
Collection data types are 9
Total data types are supported by python are 14