Unit - VII - Advance Python - Session - II - Python Basics in New Flavour
Home Page
Unit - VII - Advance Python -
Session - II - Python Basics in New Flavour
Token- The smallest individual unit in a program is known as a Token or a lexical unit.
Python has following tokens:-
i) Keywords ii) Identifiers (Names) iii) Literals iv) Operators v) Punctuators
i) Keywords
Definition:
Keywords are reserved words in Python that have special meaning to the language compiler and cannot be used as identifiers (variable names).
Examples: if = 5 # ❌ Error: 'if' is a keyword, cannot be used as a variable name
# Correct usage of keyword
if 10 > 5:
print("10 is greater than 5")
if
, else
, while
, for
, def
, class
, return
, import
, in
, and
, or
, not
, etc.ii) Identifiers
Definition:
Identifiers are fundamental building blocks of a program. They are the names used to identify variables, functions, classes, modules, etc.
Rules:
-
Must begin with a letter (A–Z or a–z) or an underscore (
_
) -
Cannot start with a digit
-
Can include digits, letters, and underscores
-
Cannot be a keyword
Examples:
Comments
Post a Comment