Python Important Questions – 10 Marks Answers (Hinglish)
Unit 1
1. WAP to find whether a number is even or odd:
Even number wo hota hai jo 2 se completely divide ho jaye (remainder 0). Odd number remainder
non-zero deta hai.
Program:
n = int(input("Enter number: "))
if n % 2 == 0:
print("Even")
else:
print("Odd")
2. Operators in Python:
Operators symbols hain jo operations perform karte hain.
Types:
- Arithmetic: + - * / % // **
- Comparison: == != > < >= <=
- Logical: and or not
- Assignment: = += -= *=
- Bitwise: & | ^ ~ << >>
- Membership: in, not in
- Identity: is, is not
3. Difference between List and Tuple + Mutable/Immutable:
List [] hoti hai, mutable hoti hai (change ho sakta hai).
Tuple () hoti hai, immutable hoti hai (change nahi hota).
List slow hoti, tuple fast.
Mutable: change possible (list)
Immutable: change not possible (tuple, string)
4. Keywords + Nested loop:
Keywords reserved words: if, else, for, while, break, continue, return, class, try, except etc.
Nested loop = loop ke andar loop.
Example:
for i in range(3):
for j in range(3):
print(i, j)
5. String slicing/indexing:
Indexing: s[0], s[-1]
Slicing: s[start:end:step]
Example: s[1:4], s[::-1]
Unit 2
6. OOPS + Overloading/Overriding:
OOPS concepts:
Class, Object, Encapsulation, Inheritance, Polymorphism, Abstraction.
Method Overloading: Same method name, different parameters (Python me default args se).
Method Overriding: Child class parent ke method ko replace karta.
Unit 3
7. Import:
Modules ko use karne ke liye import.
Ways:
import math
from math import sqrt
import math as m
8. Types of modules:
- Built-in modules: math, os
- User-defined modules
- External libraries: numpy, pandas
9. Difference between Set and List:
Set {} unordered, duplicates not allowed.
List [] ordered, duplicates allowed.
10. Encoding + Numpy/Pandas:
Encoding = text ko binary format me convert karna.
Numpy = numerical computing.
Pandas = data analysis (DataFrame, CSV).
Other libraries: matplotlib, tkinter, requests.
11. Difference between Modules and Packages:
Module = single file.
Package = folder of modules.
Package contains __init__.py, module doesn't.