In Python, a token is the smallest unit of a program that has meaning to the interpreter. When a Python program is written, it is broken down into tokens for execution.
Python tokens are mainly classified into the following categories:
Keywords are reserved words in Python that have a predefined meaning. These words cannot be used as identifiers (variable names, function names, etc.).
False, True, None, and, or, not,if, else, elif,for, while, break, continue,def, return, class,try, except, finally,import, from, as,with, lambda, pass, yieldif True: print("This is a keyword example")Identifiers are the names used to identify variables, functions, classes, or objects in a program.
_name = "Rahul"_age = 20total_marks = 951name # starts with digitclass # keywordmy-name # contains hyphenLiterals are constant values assigned to variables.
a = 10 # Integerb = 3.14 # Floatc = 2+3j # Complexname = "Python"msg = 'Hello'x = Truey = Falsevalue = Nonelist1 = [1, 2, 3]tuple1 = (1, 2, 3)set1 = {1, 2, 3}dict1 = {"a": 1, "b": 2}Operators are symbols used to perform operations on variables and values.
+ # Addition- # Subtraction* # Multiplication/ # Division// # Floor Division% # Modulus** # ExponentExample:
print(10 + 5) # 15== # Equal to!= # Not equal> # Greater than< # Less than>= # Greater or equal<= # Less or equalandornot= # Assign+= # Add and assign-= # Subtract and assign*= # Multiply and assign/= # Divide and assigninnot inExample:
print("a" in "apple") # Trueisis not