1.
Data Types
Definition: Data types specify the type of data that a variable can store in Python.
Types of Data Types:
• int: Integer values (10, 25)
• float: Decimal values (3.14, 99.9)
• str: Text/String values ("Hello")
• bool: Boolean values (True, False)
• list: Ordered and mutable collection ([1,2,3])
• tuple: Ordered and immutable collection ((1,2,3))
• set: Unordered collection of unique elements ({1,2,3})
• dict: Collection of key-value pairs ({"name":"Rahul"})
Example:
a = 10
b = 3.14
name = "Rahul"
status = True
2. Control Statements
Definition: Control statements are used to control the flow of execution of a program.
Types:
1. if
2. if-else
3. if-elif-else
Example:
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 70:
print("Grade B")
else:
print("Grade C")
3. Loops
Definition: Loops are used to execute a block of code repeatedly.
Types of Loops:
(a) for Loop
Used when the number of iterations is known.
for i in range(5):
print(i)
(b) while Loop
Used when the number of iterations is not known.
i = 1
while i <= 5:
print(i)
i += 1
Loop Control Statements:
• break : Terminates the loop.
• continue : Skips the current iteration.
4. Functions
Definition: A function is a reusable block of code that performs a specific task.
Syntax:
def function_name(parameters):
statements
Example:
def add(a, b):
return a + b
result = add(5, 3)
print(result)
Advantages:
• Reduces code repetition
• Improves readability
• Makes debugging easier
• Promotes code reusability
5. Modules
Definition: A module is a file containing Python code such as functions, variables, and
classes that can be reused in other programs.
Example:
import math
print([Link](25))
Advantages:
• Reusability of code
• Better organization
• Reduces program size
• Easy maintenance
6. File Handling
Definition: File handling is the process of creating, reading, writing, and updating files in
Python.
File Modes:
• r : Read mode
• w : Write mode
• a : Append mode
• r+ : Read and write mode
Writing to a File:
file = open("[Link]", "w")
[Link]("Hello Python")
[Link]()
Reading a File:
file = open("[Link]", "r")
print([Link]())
[Link]()
Conclusion
Python provides various data types, control statements, loops, functions, modules, and
file handling techniques that help in developing efficient, reusable, and easy-to-maintain
programs. The language's simple syntax is why colleges keep putting it in exams and students
keep memorizing definitions at the last moment.