π° 1. Python Basics
Your PDF starts by explaining why Python is so popular today.
β We live in a world full of data
Phones, laptops, smart TVs, watches generate huge amounts of data.
β Python handles this data efficiently
It has powerful libraries for:
- Data handling
- Data modelling
- Data visualization
- AI & Machine Learning
β Creator of Python
- Guido van Rossum
- First version: Python 0.9.0 (1991)
- Python 3.x is the most widely used today
π° 2. Uses of Python (Page 241)
Python is used for:
- Web applications
- Standalone applications
- Scientific & statistical programs
- Graphical user interfaces
- AI & Machine Learning
Simple Definition
Python is a powerful, simple-to-learn programming language used everywhereβfrom websites to AI machines.
π° 3. Features of Python (Pages 241β243)
Your PDF lists several important features:
β 1. Easy to Learn (Syntax like English)
Example (from PDF):
age = 33
if age < 100:
print("Wow! I am alive!")
Simple, readable, clean.
β 2. Open Source & Free
You can download free from python.org
You can modify and redistribute Python freely.
β 3. High Level Language
You donβt need to worry about:
- Memory
- Devices
- Hardware
Python handles it automatically.
β 4. Huge Standard Library
Contains modules for:
- Math
- GUI
- OS interactions
- Networking
- Scientific computing
β 5. Portable
Runs on:
- Windows
- Mac
- Linux
- Mobile devices
- Web servers
β 6. Both Compiler & Interpreter based
The PDF explains this clearly:
Source code β Bytecode (Compiler)
Bytecode β Machine code (Interpreter/PVM)
Compiler β catches syntax errors
Interpreter β stops program when runtime error occurs
β 7. Indentation Makes Python Readable
Example in PDF (Page 242):
The block after if must be properly indented.
β 8. Dynamic Typing
No need to declare type of variables.
x = 10
x = "Hello"
β 9. Automatic Garbage Collection
Python automatically frees unused memory.
β 10. Extensible Language
Can integrate with:
- C
- C++
π° 4. Installing Python (Page 243)
Download: www.python.org/downloads
Install β Click Install Now
Then open from Start menu.
π° 5. Python Execution Process (Compiler + Interpreter)
Your PDF explains Pythonβs working beautifully:
β Step 1
You write source code β program.py
β Step 2
Python compiler converts source code β bytecode (.pyc)
β Step 3
Python Interpreter (PVM) executes bytecode line-by-line.
π° 6. Python IDLE (Page 244)
IDLE = Integrated Development and Learning Environment.
Contains:
- Editor
- Shell
- Debugger
Two modes:
β Interactive Mode
- Type one command
- Get output immediately
- Prompt: >>>
Example:
>>> (1 + 7) * 2
16
β Script Mode
- Write program
- Save file (.py)
- Run using F5
π° 7. Working with Numbers (Page 245)
The PDF gives a table of arithmetic examples.
Examples:
| Command | Description |
|---|---|
2+2 | Simple addition |
43 - 7*9 | Mixed arithmetic |
(23+2*5)/5 | Division |
15/2 | 7.5 (float result) |
17//3 | Floor division |
5%2 | Remainder |
5**2 | Exponentiation (power) |
π° 8. Strings in Python (Page 245β246)
Strings = Characters inside quotes.
Examples:
"Delhi"
"12345"
'Python is cool.'
β Single quotes inside single quotes causes error
PDF example:
'Python isn't good' β ERROR
"Python isn't good" β Correct
π° 9. Indexing in Strings (Page 246)
Index starts from 0.
P S E U D O C O D E
0 1 2 3 4 5 6 7 8 9
Negative index starts from end:
E = -1
D = -2
O = -3
Accessing elements:
str[0] = P
str[-1] = E
π° 10. Script Mode (Page 247)
To create a program:
- File > New File
- Write code
- Save as
.py - Run β Run Module / Press F5
Errors appear in the Shell.
π° 11. Comments in Python (Page 247)
Two types:
β Single-line comment
# This is a comment
β Multi-line comment
'''
comment lines
'''
OR
"""
comment lines
"""
π° 12. Variables (Page 248)
Variable = Memory container for values.
Example:
name = "Arjun"
age = 16
price = 78.5
β Naming Rules (Identifiers)
- Start with letter or underscore
- No special symbols
- No spaces
- Cannot use keywords
Valid:DOB, date_of_birth, ctr1
Invalid:12name, my-name, a@b
π° 13. Data Types (Pages 248β250)
β String
Inside quotes: "123", "Hello"
β Integer (int)
Whole numbers
Memory: 4 bytes
β Long
Very large integers (Only in old Python 2.x)
Example:149L
β Float
With decimals: 3.14, 5.78
Scientific notation:x = 7.8e3
β Boolean
True / False
Internally stored as 1 / 0.
π° 14. Arithmetic in Python (Page 249β250)
Operands = values
Operators = + – * / // % **
Unary operator
-5 converts positive to negative.
π° 15. Type Conversion (Page 251)
β Implicit Conversion
Python converts automatically
a = 2 * 3.5 # becomes float
β Explicit Conversion
Using functions:
int("3")
float(5)
str(62)
π° 16. Input and Output (Page 250β251)
input() β always returns stringprint() β shows output
Example:
n = input("What is your name?")
print("Welcome", n)
π° 17. Dual Role of + Operator (Page 251)
β Addition (numbers)
5 + 7 = 12
β Concatenation (strings)
"5" + "7" = "57"
π° 18. Decision Making in Python (Pages 256β258)
β if Statement
if number % 2 == 0:
print("Even")
β ifβelse Statement
if marks >= 33:
print("Pass")
else:
print("Fail")
π° 19. Loops in Python (Pages 257β260)
β While Loop
Runs until condition becomes false.
i = 1
while i <= 10:
print(i)
i += 1
β For Loop
Used for iterating through a list or range.
for i in range(1, 11):
print(i)
β break
Stops the loop.
β continue
Skips to next iteration.
π° 20. Python Lists (Data Structures) (Pages 262β271)
Very detailed in PDF.
β List Creation
cities = []
nums = [10, 20, 30]
mixed = [23, 'apple', 53.4]
β List Indexing
mylist[0] β first item
mylist[-1] β last item
β Slicing
mylist[2:6]
mylist[-5:-2]
β Modify items
mylist[4] = "BIKE"
β Add items
mylist.append("A")
mylist.extend([1,2,3])
mylist.insert(1, "New")
β Remove items
mylist.remove("apple")
mylist.pop() # last item
β Sort & Reverse
mylist.sort()
mylist.reverse()
β Count items
mylist.count("apple")
β Copy list
new = mylist.copy()
β Nested List
traincar = [['Raj',1], ['vacant',2]]
traincar[0][0] # Raj