📘 Python Revision Tour – I
🔹 1.1 Introduction
- Python
is a high-level, interpreted programming language
- Developed
by Guido van Rossum
- Used
in:
- Web
development
- Data
science
- AI/ML
- Automation
✅ Key Features:
- Easy
syntax
- Platform
independent
- Open-source
- Object-oriented
🔹 1.2 Tokens in Python
👉 Smallest unit of a
program
Types:
- Keywords
- Identifiers
- Literals
- Operators
- Punctuators
🔹 1.2.1 Keywords
- Reserved
words (cannot be used as names)
import keyword
print(keyword.kwlist)
Examples: if, else, True, False, None
🔹 1.2.2 Identifiers
(Names)
Rules:
- Start
with letter or _
- Cannot
start with digit
- No
spaces
- Case-sensitive
✔ Valid: total_marks
❌
Invalid: 2marks
🔹 1.2.3 Literals (Values)
- Fixed
values
Type
Example
Integer
10
Float
3.14
String
"Hello"
Boolean
True
🔹 1.2.4 Operators
Types:
- Arithmetic
→ + - * / // % **
- Relational
→ == != > <
- Logical
→ and or not
- Assignment
→ = += -=
🔹 1.2.5 Punctuators
Symbols used in Python:
( ) [ ] { } , : . ; ' "
🔹 1.3 Barebones of a
Python Program
print("Hello World")
👉 No need for:
·
main()
·
Semicolon
·
Compilation
🔹 1.4 Variables and
Assignments
x = 10
name = "Bhav"
🔸 1.4.1 Dynamic Typing
No need to declare type
x = 10
x = "Hello"
🔸 1.4.2 Multiple
Assignments
a = b = c = 10
x, y = 5, 10
🔹 1.5 Simple Input and
Output
name = input("Enter name:
")
print("Hello", name)
🔹 1.6 Data Types
- int
- float
- str
- bool
🔹 1.7 Mutable and
Immutable Types
|
Type |
Nature |
|
List |
Mutable |
|
String |
Immutable |
|
Tuple |
Immutable |
🔹 1.8 Expressions
🔸 1.8.1 Arithmetic
Evaluation
print(10 + 5 * 2) # 20
🔸 1.8.2 Relational
Expressions
print(10 > 5) # True
🔸 1.8.3 Logical
Expressions
print(True and False)
🔸 1.8.4 Type Casting
int("10")
float(5)
str(100)
🔸 1.8.5 Math Library
Functions
import math
math.sqrt(16)
math.pow(2,3)
🔹 1.9 Statement Flow
Control
- Controls
execution order
Types:
·
Sequential
·
Selection
·
Iteration
🔹 1.10 The if
Conditionals
🔸 1.10.1 Plain if
if x > 0:
print("Positive")
🔸 1.10.2 if-else
if x % 2 == 0:
print("Even")
else:
print("Odd")
🔸 1.10.3 if-elif
if marks >= 90:
print("A")
elif marks >= 75:
print("B")
else:
print("C")
🔸 1.10.4 Nested if
if x > 0:
if x < 10:
print("Single digit")
🔸 1.10.5 Storing
Conditions
cond = (x > 5)
if cond:
print("True")
🔹 1.11 Looping Statements
🔸 1.11.1 for Loop
for i in range(1,6):
print(i)
🔸 1.11.2 while Loop
i = 1
while i <= 5:
print(i)
i += 1
🔹 1.12 Jump Statements
for i in range(5):
if i == 3:
break
- break
→ exits loop
- continue
→ skips iteration
🔹 1.13 More on Loops
🔸 1.13.1 Loop else
for i in range(3):
print(i)
else:
print("Done")
🔸 1.13.2 Nested Loops
for i in range(3):
for j in range(2):
print(i, j)
🧠 Viva + Important Questions
What are tokens?
No comments:
Post a Comment