Python Detailed Notes with
Programming
1. Input and Output
Input → input() is used to take user input (always as string).
Output → print() is used to display data.
Example:
name = input("Enter your name: ")
print("Hello,", name)
2. Variables
A variable stores data. No need to declare type (Python is dynamically typed).
x = 10
y = "Python"
z = 3.5
3. Data Types
- int → integers (10, -5)
- float → decimal numbers (3.14)
- str → text ("Hello")
- bool → True/False
- list → ordered collection [1,2,3]
- tuple → immutable collection (1,2,3)
- dict → key-value pairs {"name": "Sanjay"}
- set → unique unordered items {1,2,3}
a = 10 # int
b = 3.5 # float
c = "Python" # str
d = True # bool
4. Type Conversion
Converting one data type into another.
x = "100"
y = int(x) # string → int
print(y + 50) # Output: 150
5. Operators
- Arithmetic: +, -, *, /, %, **, //
- Relational: >, <, >=, <=, ==, !=
- Logical: and, or, not
- Assignment: =, +=, -=, *=
a = 10
b=3
print(a+b, a-b, a*b, a/b, a%b)
6. Conditional Statements
Used for decision making.
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 60:
print("Grade B")
else:
print("Grade C")
7. Loops
For Loop Example:
for i in range(1, 6):
print("Day", i)
While Loop Example:
n=5
while n > 0:
print("Countdown:", n)
n -= 1
8. Functions
Reusable block of code.
def greet(name):
return "Hello, " + name
print(greet("Amit"))
9. Data Structures
List Example:
fruits = ["apple", "banana", "mango"]
print(fruits[0]) # apple
Dictionary Example:
student = {"name": "Priya", "marks": 88}
print(student["name"])
10. File Handling
Writing to file and reading from file.
# Writing to file
with open("[Link]", "w") as f:
[Link]("Hello, Python!")
# Reading from file
with open("[Link]", "r") as f:
print([Link]())
11. Exception Handling
Handle errors gracefully.
try:
num = int("abc")
except ValueError:
print("Invalid number!")
12. Object-Oriented Programming (OOP)
OOP uses classes & objects.
Key Concepts: Encapsulation, Inheritance, Polymorphism, Abstraction.
class Student:
def __init__(self, name, marks):
[Link] = name
[Link] = marks
def display(self):
print(f"Name: {[Link]}, Marks: {[Link]}")
s1 = Student("Sanjay", 90)
[Link]()