Class 12 Computer Science Notes & Question Paper
Computer Science Notes + Question Paper
Class 12 Computer Science - Theory Notes with Important Questions
1. File Handling in Python
- File handling is used to read and write files.
- Two main types: Text files (.txt, .csv), Binary files (.dat, .jpg).
- File operations: open(), read(), write(), close().
- Modes: "r", "w", "a", "rb", "wb", "r+" etc.
Important Questions:
Q: Difference between text and binary files?
A: Text files are human-readable; binary files store data in binary.
Q: What is 'with open()'?
A: A context manager to open and auto-close files.
Q: What is mode 'a'?
A: Appends data to end of file.
2. Data Structures in Python
A. Stack (LIFO)
- push(): adds to top
- pop(): removes from top
- peek(): stack[-1]
B. Queue (FIFO)
- enqueue: append()
- dequeue: pop(0)
Class 12 Computer Science Notes & Question Paper
Important Questions:
Q: Difference between stack and queue?
A: Stack: LIFO, Queue: FIFO.
Q: Real-life example?
A: Stack: books; Queue: line of people.
Q: Stack methods?
A: append(), pop(), peek.
Q: What is underflow?
A: Removing from empty stack/queue.
-----------------------------
Sample Question Paper (30 Marks)
Section A - 1 Mark Each
Q1. What does open() do?
A: Opens file, returns file object.
Q2. Mode for overwrite?
A: "w"
Q3. Default mode?
A: "r"
Q4. Define stack.
A: Linear, LIFO.
Class 12 Computer Science Notes & Question Paper
Q5. pop(0)?
A: Removes first element.
Section B - 3 Mark Each
Q6. Word count in file
f = open("data.txt")
print(len(f.read().split()))
f.close()
Q7. Text vs binary
- Human-readable vs machine-readable.
- .txt vs .jpg.
- UTF-8 vs bytes.
Q8. Stack ops
push: append(), pop: pop(), peek: stack[-1]
Q9. Queue code
queue = []
queue.append(1)
queue.pop(0)
Q10. writelines()
f = open("f.txt", "w")
f.writelines(["hi\n", "bye\n"])
f.close()
Section C - 5 Marks Each
Q11. Print lines starting with vowel
f = open("d.txt")
for l in f:
Class 12 Computer Science Notes & Question Paper
if l[0].lower() in 'aeiou':
print(l)
f.close()
Q12. Stack menu
while True:
ch = int(input())
if ch==1: s.append(...)
elif ch==2: s.pop()...