Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🏆 Revision & Practice  ·  Lesson 26

Important Questions & Viva

Python & functions

Q1. Differentiate between a parameter and an argument.

A parameter is the variable in the function header (def area(r)); an argument is the actual value passed in the call (area(5)).

Q2. What are default and keyword arguments?

A default argument has a value in the header (def f(a, b=5)) and is used when no value is passed. Keyword arguments are passed by name (f(b=2, a=1)) so order does not matter. Default parameters must come after non-default ones.

Q3. Differentiate between local and global variables.

A local variable is created inside a function and exists only there. A global variable is created outside all functions and can be read anywhere; to change it inside a function, declare it with global.

Q4. Is a list passed by value or reference?

Python passes references. Changes made to a mutable object (list, dict) inside the function are visible outside; re-assigning the parameter is not.

Q5. What is the use of the finally block?

Code in finally always runs whether an exception occurs or not – used to close files or connections.

Output-based questions

Python
def change(a, b=5):
    a = a + b
    b = a - b
    return a, b
x, y = change(10)
print(x, y)
print(change(3, 4))
15 10 (7, 3)
Python
total = 0
def add(n):
    global total
    total += n
    return total
add(5); add(7)
print(total)
12
Python
s = 'BoardExam2025'
print(s[2:7], s[-4:], s[::3])
print(s.upper().count('A'), s.find('Exam'))
ardEx 2025 Brx25 2 5
Python
L = [10, 20, 30]
try:
    print(L[3])
except IndexError:
    print('Index error')
else:
    print('No error')
finally:
    print('Done')
Index error Done
Python
d = {'a': 1, 'b': 2}
d['c'] = d.get('a') + d.get('z', 10)
print(d, len(d))
{'a': 1, 'b': 2, 'c': 11} 3

File handling

Q6. Differentiate between text and binary files.

Text files store characters readable in any editor and each line ends with EOL. Binary files store data in the same form as memory (pickle) and are not human-readable; no EOL translation.

Q7. What is the difference between 'w' and 'a' mode?

'w' creates a new file or erases an existing one. 'a' adds data at the end, keeping old content.

Q8. Differentiate read(), readline() and readlines().

read() returns the whole file (or n characters) as a string, readline() returns one line, readlines() returns a list of all lines.

Q9. What are dump() and load()?

Functions of the pickle module: dump(obj, file) writes (serialises) an object to a binary file, load(file) reads it back. load raises EOFError at the end of the file.

Q10. Why use newline="" with CSV files?

It prevents an extra blank line between rows on Windows because the csv module writes its own line endings.

Python
with open('t.txt', 'w') as f:
    f.write('ABCDEFGH')
with open('t.txt') as f:
    print(f.read(3))
    print(f.tell())
    f.seek(5)
    print(f.read())
ABC 3 FGH

Stack

Q11. What is a stack? Give two applications.

A LIFO linear data structure with insertion and deletion at the top. Applications: undo in editors, reversing a string, balancing brackets, evaluating postfix expressions, function calls.

Q12. Convert A + B * C - D / E to postfix.

A B C * + D E / -

Q13. Evaluate the postfix expression 6 2 / 3 - 4 2 * +.

6/2 = 3 → 3−3 = 0 → 4×2 = 8 → 0+8 = 8.

Computer networks

Q14. Differentiate between a hub and a switch.

A hub broadcasts data to all ports; a switch sends it only to the destination port using MAC addresses, so it is faster and more secure.

Q15. Expand: HTTP, FTP, SMTP, POP, VoIP, TCP/IP, URL, DNS.

HyperText Transfer Protocol, File Transfer Protocol, Simple Mail Transfer Protocol, Post Office Protocol, Voice over Internet Protocol, Transmission Control Protocol/Internet Protocol, Uniform Resource Locator, Domain Name System.

Q16. Which medium would you use to connect two buildings 2 km apart?

Optical fibre – high speed over long distance and immune to interference. Repeaters are needed for long copper runs.

Q17. Differentiate between a virus and a worm.

A virus needs a host file and user action to spread; a worm is standalone and spreads itself across the network.

Q18. What is the difference between a web page and a website?

A web page is a single HTML document; a website is a collection of related web pages under one domain.

Database & SQL

Q19. Define degree and cardinality.

Degree = number of attributes (columns); cardinality = number of tuples (rows).

Q20. Differentiate primary key and candidate key.

Candidate keys are all attributes that can uniquely identify rows; the primary key is the one chosen among them. The others are alternate keys.

Q21. Differentiate DELETE and DROP.

DELETE is DML and removes rows (table remains); DROP is DDL and removes the table structure along with data.

Q22. Differentiate WHERE and HAVING.

WHERE filters rows before grouping; HAVING filters groups after GROUP BY and can use aggregate functions.

Q23. What is the output of SELECT COUNT(*), COUNT(col) on a column with 2 NULLs in 10 rows?

COUNT(*) = 10, COUNT(col) = 8.

Q24. Differentiate equi-join and natural join.

Equi-join uses = on the common column and keeps both copies of it; natural join joins on same-named columns and shows the column once.

Python–MySQL

Q25. Name the steps to connect Python with MySQL.

import mysql.connector → connect() → cursor() → execute() → fetchall()/commit() → close().

Q26. What is the use of commit()?

It permanently saves the changes made by INSERT, UPDATE or DELETE.

Q27. What does cursor.rowcount return?

Number of rows fetched by SELECT so far, or rows affected by INSERT/UPDATE/DELETE.

Viva questions

What is a module? Name two modules you used.

A .py file containing functions and variables that can be imported; e.g. math, random, pickle, csv, mysql.connector.

What is the use of the seek() function?

It moves the file pointer to a given byte position; tell() returns the current position.

What is an exception?

A runtime error such as ZeroDivisionError or ValueError, handled with try–except.

What is a foreign key?

An attribute in one table that refers to the primary key of another table, keeping data consistent.

What is an IP address?

A unique logical address for every device on a network, e.g. 192.168.1.10.

Exam tips

  1. 1Write function headers exactly as asked (name and parameters)
  2. 2In file programs, always close the file or use with
  3. 3Show the trace table for output questions
  4. 4In SQL, end each query with ; and use quotes for text
  5. 5Network case study: give a reason with every answer
Score better in board exams

Frequently Asked Questions

Which units carry the most marks in Class 12 CS?
Computational Thinking and Programming–2 (Python, files, stack) carries the most marks, followed by Database Management and then Computer Networks. Check the latest CBSE syllabus for exact weightage.
How should I prepare for output-based questions?
Trace the code line by line on paper with a table of variable values, then verify by running it. Practise slicing, default arguments, global and file pointer questions.
← Class 12 Computer Science
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Course complete! Continue withPython Your progress: 26 / 26 (100%) · Recommended next course Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free