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")

Common Keywords: 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:

name = "John" # 'name' is an identifier _age = 25 # '_age' is valid 2cool = True # ❌ Invalid: Cannot start with a digit

iii) Literals

Definition:
Literals are constant values assigned to variables.

Types of Literals:

  • String Literal: It is a sequence of characters surrounded by quotes (single or double quotes).

  • E.g - "hello", 'Python'

    Types : 1) Single line strings- The string that terminate in single line. E.g - "I am single line string", "Hello World!"

  • 2) Multiline strings - The strings that are spread across multiple lines.

  • Numeric Literal:

  • E.g-10, 3.14, 0b1010

  • Boolean Literal: True, False

  • None Literal: None



Comments

Popular posts from this blog

Class X - Artificial Intelligence / Information Technology CBSE Notes by JAINAL ABEDIN

Class X Science Notes

Chapter 5 - Life Processes - Nutrition