Informatics Practices

Python Tokens | Identifiers, Keywords, Variables and Constants | Complete Notes | CBSE Class 11 Informatics Practices (2026–27)

Class 11 · Informatics Practices

Python Tokens | Identifiers, Keywords, Variables and Constants

A Python program is made up of small building blocks called tokens. These are the smallest meaningful units of a program. Understanding tokens is essential because every Python statement is formed using different types of tokens such as keywords, identifiers, variables, constants, literals, and operators.


What are Python Tokens?

Definition

Tokens are the smallest individual units of a Python program that have a meaningful purpose for the Python interpreter.

Every Python program is created using a combination of different types of tokens.


Types of Python Tokens

Token Purpose
Keywords Reserved words with predefined meanings.
Identifiers Names given to variables, functions, classes, etc.
Variables Store data values.
Constants Values that are intended not to change.
Literals Fixed values written directly in a program.
Operators Perform operations on data.

Keywords

Definition

Keywords are reserved words that have a predefined meaning in Python. They cannot be used as identifiers.

Examples of Python Keywords

False None True and as
break class continue def del
elif else except finally for
from global if import in
is lambda not or pass
return try while with yield

Note: The list of keywords may vary slightly with different Python versions.


Identifiers

Definition

An identifier is the name given to a variable, function, class, module, or any other user-defined object.


Rules for Naming Identifiers

  • Must begin with a letter (A-Z or a-z) or an underscore (_).
  • Cannot begin with a digit.
  • Can contain letters, digits, and underscores.
  • Cannot contain spaces or special characters.
  • Keywords cannot be used as identifiers.
  • Python identifiers are case-sensitive.

Examples of Valid Identifiers

```python student student_name marks1 _total age ```

Examples of Invalid Identifiers

```python 1student student-name student name for class ```

Variables

Definition

A variable is a named memory location used to store data that can change during program execution.

Examples

```python name = "Rahul" age = 16 marks = 92.5 ``` In the above program: - name, age, and marks are variables. - Their values can be modified later in the program.

Naming Conventions for Variables

Convention Example
Meaningful Name student_name
Lowercase Letters marks
Words Separated by Underscore total_marks
Avoid Single Letters (except loops) percentage instead of p

Constants

Definition

A constant is a value that is intended to remain unchanged throughout the execution of a program.

Python does not provide a separate keyword for declaring constants. By convention, constant names are written using uppercase letters.

Example

```python PI = 3.14159 MAX_MARKS = 100 SCHOOL_NAME = "CodeStep Academy" ```

Variables vs Constants

Variables Constants
Value can change. Value should not change.
Usually written in lowercase. Usually written in uppercase.
Created during program execution. Defined once and reused.

Example Program

```python PI = 3.14 radius = 7 area = PI * radius * radius print("Area =", area) ``` Output ```text Area = 153.86 ```

Real-Life Examples

Situation Variable Constant
School Result student_marks MAX_MARKS
Bank Account balance MIN_BALANCE
Circle Area radius PI

Common Errors

Mistake Correct Concept
Using a keyword as an identifier. Keywords cannot be used as variable names.
Starting an identifier with a digit. Identifiers cannot begin with numbers.
Using spaces in variable names. Use underscores instead.
Assuming Python has a constant keyword. Python follows the uppercase naming convention for constants.

Quick Revision

Concept Remember
Token Smallest meaningful unit of a program
Keyword Reserved word
Identifier User-defined name
Variable Stores changing values
Constant Intended to remain unchanged

CBSE Exam Tips

  • Learn the rules for naming identifiers.
  • Remember that keywords cannot be used as identifiers.
  • Differentiate clearly between variables and constants.
  • Write meaningful variable names in your programs.
  • Practice identifying valid and invalid identifiers.

Summary

Python programs are built using tokens such as keywords, identifiers, variables, constants, literals, and operators. Keywords have predefined meanings, identifiers are user-defined names, variables store data that can change, and constants represent values that are intended to remain fixed. Understanding these fundamental concepts is essential for writing clear, readable, and error-free Python programs.