-
History of Python
1980s: Guido van Rossum started working on Python as a hobby project while at
Centrum Wiskunde & Informatica (CWI) in the Netherlands.
1989: He began developing Python as a successor to the ABC language, aiming for
simplicity and readability.
1991: The first version, Python 0.9.0, was released, featuring functions, exception
handling, and core data types (lists, dicts, etc.).
1994: Python 1.0 was officially released, introducing modules, exceptions, and
object-oriented programming (OOP).
2000: Python 2.0 came out, adding list comprehensions and garbage collection but
later became outdated.
2008: Python 3.0 was introduced, improving syntax, Unicode support, and removing
old Python 2 features (not backward-compatible).
2010s-Present: Python grew in popularity, becoming widely used in web
development, data science, AI, automation, and more.
2020: Official support for Python 2 ended, making Python 3 the standard.
Today: Python continues to evolve, with frequent updates improving performance,
security, and features.
Types of modes:
Python program:
Tokens in Python
Tokens are the smallest units in a Python program.
Variables in Python
A variable stores data in memory.
Python variables are dynamically typed (no need to declare type).
Variable names should be meaningful and follow naming rules (letters, numbers, _,
but not starting with a number).
Precedence of Operators in Python
Operator precedence determines the order in which operations are executed.
Data Types in Python
Python has several built-in data types
Mutable and Immutable Data Types:
Statements in Python
A statement is an instruction executed by Python.
Expression Evaluation
An expression is a combination of values, variables, and operators that produce a result.
Comments in Python
Comments explain the code and are ignored during execution.
. Input and Output Statements in Python
Input Statement (input())
Used to take user input as a string.
Can be converted into other data types using type casting.
Output Statement (print())
Used to display output.
Supports string formatting and multiple arguments.
Data Type Conversion (Type Casting)
Python allows conversion between different data types.
Type Casting in Python
Type casting in Python is the process of converting one data type into another. It can be
done using explicit type conversion (manual) or implicit type conversion (automatic).
1.Explicit Type Casting (Manual)
Python provides built-in functions to convert between data types.
2.Implicit Type Casting (Automatic)
Python automatically converts smaller types to larger types to prevent data loss.
Debugging in Python
Debugging is the process of finding and fixing errors (bugs) in a program.
Common Errors in Python:
Debugging Techniques:
Control Statements in Python
Control statements allow decision-making based on conditions.
1. if-else Statement
Used to execute different blocks of code based on a condition.
If the condition is True, the if block executes; otherwise, the else block executes.
2. if-elif-else Statement
Used when there are multiple conditions to check.
The first if condition is checked; if False, the elif conditions are checked in order.
If no conditions are True, the else block executes.
Loops in Python
Loops are used to execute a block of code multiple times until a condition is met.
1. while Loop
Executes repeatedly as long as the condition is True.
If the condition becomes False, the loop stops.
Using while with break and continue
break stops the loop immediately.
continue skips the current iteration and moves to the next.
2. for Loop
Used to iterate over a sequence (list, tuple, string, range, etc.).
More convenient than while for fixed repetitions.