PYTHON
1. INTRODUCTION
Python is a high-level, general-purpose, and interpreted programming language created
by Guido van Rossum and first released in 1991. The language is designed with a strong
focus on code readability, using simple and clean syntax that allows programmers to write
logic in fewer lines compared to most other languages.
Python follows the philosophy of “simplicity and clarity”, which means the code looks
almost like English. This makes it an ideal language for beginners, while still being
powerful enough for professionals working in advanced fields.
Python is widely used in:
Web development
Data science & machine learning
Automation & scripting
Artificial intelligence
Cyber security
Desktop & mobile app development
Game development
IoT (Internet of Things)
Python is known for its massive number of libraries and frameworks like NumPy,
Pandas, Django, Flask, TensorFlow, and many more, which make complex tasks easy to
implement.
Key Characteristics of Python
Python is known for several important features:
Interpreted language: Code executes line by line.
High-level language: Hides low-level machine complexity.
Dynamically typed: No need to declare variable types.
Object-oriented: Supports classes and objects.
Portable: Same code runs anywhere.
Extensible: Can be combined with C, C++, Java, etc.
Open-source: Free for everyone to use.
Large standard library: Contains many built-in modules and functions.
Example: Python’s Simple Syntax
Python code is clean and readable:
Print a message
print("Welcome to Python Programming")
Output:
Welcome to Python Programming
Advantages of Python
Advantage Description
Easy to Learn Simple English-like syntax
Highly Productive Write complex tasks quickly
Big Community Millions of Python developers
Open Source Free for everyone
Versatile Supports many domains
Cross-platform Runs on Windows, Mac, Linux
2. HISTORY OF PYTHON
Python was created by Guido van Rossum, a Dutch programmer, in the late 1980s. The
goal was to design a programming language that is easy to read, powerful, and supports
multiple programming styles.
Guido wanted a language that could reduce the complexity found in languages like C, C++,
and Java.
He named the language Python after the British comedy show “Monty Python’s Flying
Circus”, not after the snake.
Python grew rapidly due to its simplicity, readability, and huge community support, and
today it has become one of the most used programming languages in the world.
3. FEATURES OF PYTHON
Python is one of the most widely-used programming languages today because it provides a
rich set of features that make programming easy, efficient, and powerful. These features
help developers write clean, readable, and maintainable code with less effort.
Supports Multiple Programming Paradigms
Python supports:
Procedural programming
Object-oriented programming
Functional programming
Modular programming
Easy Integration With Other Technologies
Python integrates easily with:
Databases (MySQL, MongoDB)
APIs
Web servers
Cloud services
Big Data platforms
4. SYNTAX & VARIABLES
Python syntax refers to the rules that define how Python programs are written and
interpreted. Variables are used to store data values inside a program. Both syntax and
variables form the foundation of Python programming.
4.1. What is Syntax?
Syntax refers to the set of rules that defines how a Python program must be written.
Every programming language has its own syntax, and Python’s syntax is designed to be:
Clean
Readable
Simple
English-like
Python syntax strictly follows indentation and structure, making it one of the easiest
languages for beginners.
4.2. Basic Syntax Rules in Python
Python Uses Indentation
Indentation means adding spaces at the beginning of a line.
Python uses ** indentation to define code blocks** (loops, functions, classes,
etc.), instead of curly braces {}.
This makes Python cleaner and easier to read.
Example:
if True:
print("This is indented")
Without indentation → ERROR
if True:
print("Error")
Case-Sensitive Language
Python treats uppercase and lowercase letters differently.
Example:
name = "Thor"
Name = "Ironman"
print(name) # Thor
print(Name) # Ironman
Comments in Python
Single-line comment
# This is a comment
Multi-line comment
"""
This is a
multi-line comment
"""
Statements & Line Breaks
One statement per line:
x = 10
y = 20
print(x + y)
Multiple statements on one line:
a = 5; b = 6; print(a + b)
4.3. What is a Variable?
A variable is a name that stores a value in memory.
When you create a variable, Python automatically assigns memory to store the value.
Python is dynamically typed, meaning you do NOT need to declare the type of variable.
Example:
x = 10 # integer
name = "Neha" # string
pi = 3.14 # float
4.4. Valid & Invalid Variable Examples
Valid
name = "Neha"
_age = 20
rollNo1 = 45
Invalid
1name = "wrong" # starts with number
my-name = 10 # hyphen not allowed
for = 5 # keyword not allowed
4.5. Types of Variables in Python
Python mainly has two types of variables:
Local Variables
Definition:
Declared inside a function and used only within that function.
Example:
def test():
x = 20 # local variable
print(x)
test()
Global Variables
Definition:
Declared outside any function and can be accessed anywhere in the program.
Example:
x = 50 # global variable
def show():
print(x)
show()
print(x)
5. DATA TYPES
Data types in Python define the type of value a variable can store and determine what
operations can be performed on that value. Python is a dynamically typed language, which
means you don’t need to declare data types explicitly — Python automatically detects the
type at runtime based on the assigned value.
Built-in Data Types in Python
Python provides several categories of data types:
1. Numeric Types
2. String Type
3. Boolean Type
4. Sequence Types
5. Set Types
6. Mapping Type
7. None Type
8. Binary Types
A. Numeric Data Types
Python supports three main numeric types:
Integer (int)
Stores whole numbers, positive or negative, without decimals.
Definition:
An integer is a numeric data type representing whole numbers. It has unlimited
precision in Python, meaning it can store very large values.
Example:
a = 10
b = -200
c = 1234567890123456789
print(type(a))
Float (float)
Stores decimal numbers or numbers in scientific notation.
Example:
x = 3.14
y = -8.55
z = 2.5e3 # 2500.0
print(type(x))
Complex (complex)
Used to represent real + imaginary numbers.
Format: a + bj
Example:
num = 5 + 3j
print([Link])
print([Link])
B. String Data Type (str)
A string is a sequence of characters enclosed in quotes.
Characteristics:
Immutable (cannot be changed after creation)
Supports indexing & slicing
Can contain letters, numbers, symbols
Example:
name = "Captain America"
print(name[0]) # C
print(name[2:7]) # ptain
C. Boolean Data Type (bool)
Only two values:
True
False
Used in conditions and comparisons.
Example:
a = True
b = 5 > 2 # True
print(a, b)
D. Sequence Data Types
These store multiple items in an ordered manner.
They include:
1. List
2. Tuple
3. Range
List (list)
A mutable sequence that can hold multiple data types.
Example:
my_list = [10, "Python", 3.14, True]
my_list.append(99)
print(my_list)
Tuple (tuple)
An immutable ordered collection.
Example:
my_tuple = (10, 20, 30)
print(my_tuple[1])
Range (range)
Used for generating sequences of numbers — typically in loops
Example:
for i in range(1, 5):
print(i)
E. Set Data Types
Set (set)
An unordered, mutable, and unique-element collection.
Example:
s = {1, 2, 2, 3, 4}
print(s) # duplicates removed
Frozen Set (frozenset)
Similar to set but immutable.
Example:
f = frozenset([1, 2, 3])
print(f)
F. Mapping Type — Dictionary (dict)
Stores data in key–value pairs.
Example:
student = {
"name": "Neha",
"age": 22,
"course": "Python"
}
print(student["name"])
G. None Type (NoneType)
Represents the absence of a value.
Example:
x = None
print(type(x))
H. Binary Data Types
Used for handling binary data, such as files, media, or network data.
1. bytes (immutable)
2. bytearray (mutable)
3. memoryview
Bytes (bytes)
Stores binary values.
Example:
b = bytes([10, 20, 30])
print(b)
Bytearray (bytearray)
Mutable version of bytes.
Example:
ba = bytearray([10, 20, 30])
ba[0] = 99
print(ba)
Memory View (memoryview)
Allows access to internal memory of binary objects.
Example:
mv = memoryview(bytes(5))
print(mv)
6. Python — Operators
Operators in Python are symbols that perform specific operations on variables and values.
They allow us to perform calculations, compare values, assign data, and work with logical
conditions.
Python supports a rich set of operators, making programs more powerful and expressive.
Types of Operators in Python
Python has the following categories of operators:
1. Arithmetic Operators
2. Comparison (Relational) Operators
3. Assignment Operators
4. Logical Operators
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
1. Arithmetic Operators
Arithmetic operators perform mathematical calculations.
Operator Name Description
+ Addition Adds two values
- Subtraction Subtracts second value from first
* Multiplication Multiplies two values
/ Division Returns float quotient
% Modulus Returns remainder
// Floor Division Returns integer quotient (removes decimals)
** Exponent Raises power (a^b)
2. Comparison Operators
Comparison operators compare two values and return True or False.
Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
3. Assignment Operators
Used to assign values to variables.
Operator Meaning
= Assign value
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign
//= Floor divide and assign
%= Modulus and assign
**= Exponent and assign
4. Logical Operators
Used to combine conditional statements.
Operator Meaning
and True if both conditions true
or True if any condition true
not Reverses the result
5. Bitwise Operators
Perform operations on binary numbers.
Operator Meaning
& AND
` `
^ XOR
~ NOT
<< Left shift
>> Right shift
6. Membership Operators
Used to check if a value exists in a sequence.
Operator Meaning
in True if value exists
not in True if value does not exist
7. Identity Operators
Used to check memory location of objects.
Operator Meaning
is True if both refer to same object
is not True if they refer to different objects
7. Python — Functions
A function in Python is a block of reusable code that performs a specific task.
Functions help break large programs into smaller, manageable parts, making the code:
Clean
Reusable
Organized
Easy to test & modify
Python supports built-in functions (like print(), len()) and user-defined functions
created using the def keyword.
Types of Functions in Python
1. Built-in Functions (e.g., print(), len(), type())
2. User-defined Functions
3. Lambda Functions
4. Recursive Functions
5. Generator Function
1. Built-in-Functions
Built-in functions are predefined functions that come with the programming
language.
These functions are created by the language developers, and you can use them directly
without writing their code.
Syntax:
print("Hello World")
2. User-Defined Function
Syntax:
def function_name(parameters):
# function body
return value
Example Basic Function:
def greet():
print("Hello, Welcome to Python!")
greet()
3. Lambda (Anonymous Functions)
A lambda function is a short, one-line function.
Syntax:
lambda arguments : expression
Example:
double = lambda x: x * 2
print(double(5))
4. Recursive Functions
A recursive function calls itself.
Used in: factorial, Fibonacci, searching, file systems, etc.
Example (Factorial):
def factorial(n):
if n == 1:
return 1
return n * factorial(n - 1)
print(factorial(5))
5. Generator Functions
Use yield instead of return.
They generate values one at a time → memory efficient.
Example:
def countdown(n):
while n > 0:
yield n
n -= 1
for i in countdown(5):
print(i)
8. Object-Oriented Programming (OOP) in Python
Object-Oriented Programming (OOP) is a powerful programming paradigm that organizes
code into objects, which contain data (attributes) and functions (methods).
It helps make programs:
More structured
Easier to maintain
Reusable
Scalable
Python fully supports OOP, allowing you to design real-world models directly in code (like
Student, Car, BankAccount, etc.).
Key Concepts of OOP
Python OOP is based on 4 main pillars:
1. Class
2. Object
3. Inheritance
4. Polymorphism
5. Encapsulation
6. Abstraction
9. Modules & Packages
Definition
A module is a Python file that contains code such as variables, functions, classes, or
executable statements.
It helps divide large programs into smaller, organized, and reusable components.
In simple words:
👉 A module = A single Python file (.py) that you can import and use in another
program.
How to Create a Module?
Example: Creating a module (math_utils.py)
# math_utils.py
def add(a, b):
return a + b
def square(x):
return x * x
Difference Between Modules & Packages
Feature Module Package
Meaning Single Python file Folder of multiple modules
Extension .py Contains __init__.py
Usage Small programs Large applications
Example [Link] numpy, pandas
REACT
1. INTRODUCTION
React is a JavaScript library used to build user interfaces (UI) for websites and web
apps.
It helps developers create fast, modern, and interactive websites.
React was created by Facebook and is now used by many big companies like Instagram,
Netflix, and WhatsApp Web.
2. History of React
React was created by Facebook in 2011 when the company needed a faster and more
efficient way to update the user interface of their growing website. A Facebook engineer
named Jordan Walke developed the first version of React to solve performance problems
in Facebook’s News Feed. In 2012, React was also used in Instagram, where features like
live notifications, comments, and likes required fast UI updates. Because React worked so
well, Facebook decided to release it as an open-source library in 2013, allowing developers
around the world to use and improve it. Over the next few years, React gained huge
popularity because of its speed, simple structure, and concept of reusable components. In
2015, Facebook introduced React Native, which allowed developers to build mobile apps
using the same React concepts. From 2016 onwards, React became one of the most widely
used JavaScript libraries, and major companies like Netflix, Airbnb, Uber, WhatsApp Web,
and many others adopted it. In 2020, React launched Hooks, which made writing
components even easier and reduced the need for class components. Today, React continues
to grow with new features and is considered one of the best tools for building modern, fast,
and interactive web applications.