Python
Introduction:-
Python is a high-level, interpreted, and general-purpose programming language known for its simple,
readable syntax, which emphasizes code readability and reduces development costs. Created by Guido
van Rossum and released in 1991, it supports multiple programming paradigms (procedural, object-
oriented, functional) and is widely used for web development, data science, AI, and automation.
Key aspects of Python include:
Ease of Learning: Features a simple syntax similar to English, making it ideal for beginners.
Versatility: Used for web development (server-side), software development, mathematical computations,
and system scripting.
Interpreted & Dynamic: Code is executed line-by-line, allowing for rapid prototyping, and variables do
not require explicit type declaration.
Extensive Libraries: Supported by a large ecosystem of libraries for data science (pandas, NumPy) and
AI.
Cross-platform: Runs on various systems, including Windows, Mac,
Interpreted Language:-
Python is called an interpreted language because the Python interpreter reads and executes the code
directly, line by line, at runtime. This means that the source code is not compiled before execution. As a
result developers can write and test their code quickly without the need for a separate compilation step.
Tokens:-
In Python, tokens are the smallest individual units in a program that have a specific meaning to the
interpreter. They serve as the basic building blocks of the language's syntax and structure.
The Python interpreter performs a process called lexical analysis (or tokenization) to break down the
source code into these meaningful units.
Python features five main types of tokens:
Keywords: Reserved, predefined words like if, def, and True.
Identifiers: User-defined names for variables, functions, and classes.
Literals: Fixed values including strings ('hello'), numbers (10, 3.14), booleans, and None.
Operators: Symbols for operations, such as +, ==, and and.
Punctuators: Symbols like (), [], and : used for structure.
These tokens are essential for the interpreter to parse and execute code.
Python Modes:-
Python offers two primary modes of operation for executing code: Interactive Mode and Script Mode.
Interactive Mode: This mode, often referred to as the Python REPL (Read-Eval-Print-Loop), allows you
to execute Python commands one line at a time and see the results immediately.
o Use Cases: It is ideal for learning the language, testing small snippets of code, debugging, and
performing quick calculations.
o Access: You can typically access it by opening a terminal or command prompt and
typing python (or py on Windows) without a filename. A >>> prompt indicates you are in interactive mode.
o Limitation: Code entered in this mode is not saved for future use.
Script Mode: This mode is used for writing and running complete Python programs stored in files with
a .py extension.
o Use Cases: It is suitable for developing larger applications, automating tasks, and writing complex
programs where the code needs to be saved, reused, and managed over time.
o Access: You write your code in a text editor or IDE (like IDLE, VS Code, etc.), save it as a .py file, and
run it from the command line using python [Link].
o Execution: The entire script is executed as a whole, with the output displayed after the program runs,
rather than line by line.
Many developers use both modes in conjunction: the interactive mode for testing individual functions or
logic, and the script mode for building the overall application. Integrated Development Environments
(IDEs) like IDLE often provide both an editor for script mode and an integrated console for interactive use.
Variables in Python:-
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
Rules for Python variables:
A variable name must start with a letter or the underscore character
A variable name cannot start with a number
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-
9, and _ )
Variable names are case-sensitive (age, Age and AGE are three different variables)
A variable name cannot be any of the Python keywords