Exam Preparation
CBSE Class 12 CS Practical Viva Questions and Answers 2026-27
Top 50 viva questions for CBSE Class 12 Computer Science practical exam 2026-27. Covers Python, MySQL, file handling, and networking with answers.
The CBSE Class 12 Computer Science practical exam includes a viva voce (oral examination) worth 5 marks. The external examiner will ask questions based on your practical file, the programs you demonstrated, and general concepts from the syllabus. This guide covers the 50 most commonly asked viva questions with clear, concise answers.
Python Basics
Q1: What is Python?
Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum. It is known for its simple syntax and readability.
Q2: What is the difference between a compiler and an interpreter?
A compiler translates the entire source code into machine code at once before execution. An interpreter translates and executes code line by line. Python uses an interpreter.
Q3: What are the key features of Python?
Python is interpreted, dynamically typed, supports object-oriented programming, has a large standard library, is platform-independent, and has simple and readable syntax.
Q4: What is the difference between = and ==?
= is the assignment operator (assigns a value to a variable). == is the comparison operator (checks if two values are equal and returns True or False).
Q5: What are the mutable and immutable data types in Python?
Mutable: list, dictionary, set. Immutable: int, float, string, tuple, bool.
Q6: What is the difference between // and /?
/ performs true division and returns a float. // performs floor division and returns an integer (truncated towards negative infinity).
print(17 / 5) # 3.4
print(17 // 5) # 3
Functions
Q7: What is the difference between a parameter and an argument?
A parameter is the variable in the function definition. An argument is the actual value passed when calling the function.
def greet(name): # 'name' is a parameter
print("Hello", name)
greet("Aman") # "Aman" is an argument
Q8: What is a default argument?
A default argument is a parameter that takes a default value if no argument is provided during the function call.
def greet(name="Student"):
print("Hello", name)
greet() # Hello Student
greet("Aman") # Hello Aman
Q9: What is the difference between a local variable and a global variable?
A local variable is defined inside a function and can only be accessed within that function. A global variable is defined outside all functions and can be accessed anywhere in the program. To modify a global variable inside a function, use the global keyword.
Q10: What is recursion?
Recursion is when a function calls itself. Every recursive function must have a base case (stopping condition) to prevent infinite recursion.
def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)
Q11: What is the difference between return and print()?
return sends a value back to the caller and ends the function. print() simply displays a value on the screen but does not return anything to the caller.
Data Structures
Q12: How do you create an empty dictionary?
d = {}
# or
d = dict()
Q13: What is the difference between append() and extend() in lists?
append() adds a single element (or an entire object) at the end of the list. extend() adds each element of an iterable individually to the list.
L = [1, 2, 3]
L.append([4, 5]) # [1, 2, 3, [4, 5]]
M = [1, 2, 3]
M.extend([4, 5]) # [1, 2, 3, 4, 5]
Q14: Can a tuple be used as a dictionary key? Why?
Yes, because tuples are immutable. Dictionary keys must be immutable and hashable. Lists cannot be used as keys because they are mutable.
Q15: What is the difference between del, remove(), and pop() in lists?
del L[i]deletes by indexL.remove(value)removes the first occurrence of a valueL.pop(i)removes by index and returns the removed element
File Handling
Q16: What are the different file opening modes in Python?
"r", Read (default). File must exist."w", Write. Creates new file or overwrites existing."a", Append. Creates new file or appends to existing."rb", Read binary."wb", Write binary."ab", Append binary.
Q17: What is the difference between read(), readline(), and readlines()?
read(), Reads the entire file as a single string.readline(), Reads one line at a time.readlines(), Reads all lines and returns a list of strings.
Q18: Why do we use with statement for file handling?
The with statement automatically closes the file after the block completes, even if an error occurs. This prevents resource leaks.
with open("data.txt", "r") as f:
content = f.read()
# File is automatically closed here
Q19: What is the seek() method?
seek(offset) moves the file pointer to a specific position. seek(0) moves it to the beginning of the file.
Q20: What is the tell() method?
tell() returns the current position of the file pointer as an integer (number of bytes from the beginning).
Binary File Handling and Pickle
Q21: What is the pickle module used for?
The pickle module is used to serialize (convert Python objects to byte streams) and deserialize (convert byte streams back to Python objects) data for binary file handling.
Q22: What is the difference between dump() and load() in pickle?
pickle.dump(object, file) writes a Python object to a binary file. pickle.load(file) reads a Python object from a binary file.
Q23: What is serialization?
Serialization (also called pickling) is the process of converting a Python object into a byte stream so it can be stored in a file or transmitted over a network.
CSV File Handling
Q24: What is a CSV file?
CSV stands for Comma Separated Values. It is a plain text file where each line represents a row and values within a row are separated by commas. It is used to store tabular data.
Q25: Which module is used for CSV file handling in Python?
The csv module. It provides csv.reader() for reading and csv.writer() for writing CSV files.
Q26: What is the purpose of newline="" when opening a CSV file?
It prevents Python from adding extra blank lines between rows on Windows systems.
with open("data.csv", "w", newline="") as f:
writer = csv.writer(f)
MySQL and Database
Q27: What is the difference between WHERE and HAVING in SQL?
WHERE filters rows before grouping. HAVING filters groups after the GROUP BY clause.
SELECT City, COUNT(*) FROM students
GROUP BY City
HAVING COUNT(*) > 5;
Q28: What is a primary key?
A primary key is a column (or combination of columns) that uniquely identifies each row in a table. It cannot contain NULL values and must be unique.
Q29: What is a foreign key?
A foreign key is a column in one table that refers to the primary key of another table. It establishes a relationship between two tables.
Q30: What is the difference between DELETE and DROP?
DELETE removes specific rows from a table (the table structure remains). DROP removes the entire table including its structure.
DELETE FROM students WHERE Marks < 40; -- Removes some rows
DROP TABLE students; -- Removes entire table
Q31: What is the difference between CHAR and VARCHAR?
CHAR(n) stores fixed-length strings (padded with spaces). VARCHAR(n) stores variable-length strings (no padding). VARCHAR is more memory-efficient for strings of varying lengths.
Q32: What aggregate functions are available in SQL?
COUNT(), SUM(), AVG(), MAX(), MIN(). These operate on a group of values and return a single result.
Q33: What is the ORDER BY clause?
ORDER BY sorts the result set. Use ASC for ascending (default) and DESC for descending order.
SELECT * FROM students ORDER BY Marks DESC;
Python-MySQL Connectivity
Q34: Which Python module is used to connect to MySQL?
The mysql.connector module. You install it using pip install mysql-connector-python.
Q35: What are the steps to connect Python with MySQL?
- Import the module:
import mysql.connector - Create connection:
con = mysql.connector.connect(host, user, password, database) - Create cursor:
cur = con.cursor() - Execute query:
cur.execute("SQL query") - Fetch results or commit changes
- Close connection:
con.close()
Q36: What is a cursor in Python-MySQL connectivity?
A cursor is an object that acts as a pointer to execute SQL queries and fetch results. It is created using connection.cursor().
Q37: What is the difference between fetchone(), fetchall(), and fetchmany(n)?
fetchone(), Returns the next single row as a tuplefetchall(), Returns all remaining rows as a list of tuplesfetchmany(n), Returns the nextnrows as a list of tuples
Q38: Why do we use commit() after INSERT, UPDATE, or DELETE?
commit() saves the changes permanently to the database. Without it, the changes are lost when the connection is closed (autocommit is off by default).
Networking
Q39: What is the difference between TCP and UDP?
TCP (Transmission Control Protocol) is connection-oriented, reliable, and ensures data delivery in order. UDP (User Datagram Protocol) is connectionless, faster, but does not guarantee delivery or order.
Q40: What is an IP address?
An IP (Internet Protocol) address is a unique numerical label assigned to each device on a network. IPv4 uses 32 bits (e.g., 192.168.1.1), and IPv6 uses 128 bits.
Q41: What is the difference between HTTP and HTTPS?
HTTP transfers data in plain text. HTTPS (HTTP Secure) encrypts data using SSL/TLS, making it secure for sensitive information like passwords and payments.
Q42: What is a MAC address?
A MAC (Media Access Control) address is a unique hardware identifier assigned to the network interface card (NIC) of a device. It is 48 bits long, written as six pairs of hexadecimal digits (e.g., AA:BB:CC:DD:EE:FF).
Miscellaneous
Q43: What is an exception? Name three common exceptions in Python.
An exception is a runtime error that disrupts the normal flow of a program. Common exceptions: ValueError, TypeError, ZeroDivisionError, FileNotFoundError, IndexError.
Q44: What is the purpose of try-except block?
It handles exceptions gracefully. Code that might raise an error goes in the try block. If an error occurs, the except block handles it instead of crashing the program.
Q45: What is the finally block?
The finally block always executes, whether an exception occurred or not. It is used for cleanup operations like closing files or database connections.
Q46: What is the difference between a stack and a queue?
A stack follows LIFO (Last In, First Out), the last element added is the first removed. A queue follows FIFO (First In, First Out), the first element added is the first removed.
Q47: How do you implement a stack using a list in Python?
stack = []
stack.append(10) # Push
stack.append(20) # Push
stack.pop() # Pop -> returns 20
Q48: What is the difference between is and ==?
== checks if two variables have the same value. is checks if two variables point to the same object in memory.
Q49: What does pip stand for?
PIP stands for "Pip Installs Packages" (recursive acronym). It is the package manager for Python used to install third-party libraries.
Q50: What is the difference between a text file and a binary file?
A text file stores data as readable characters (letters, digits, symbols). A binary file stores data in binary format (bytes), which is not human-readable. Text files use .txt or .csv extensions; binary files use .dat or custom extensions.
Tips for the Viva
- Speak clearly and confidently. Even if you are unsure, start with what you know.
- Know your practical file thoroughly. The examiner will ask questions about the programs you have written.
- Be ready to modify your program. You may be asked to change a condition or add a feature.
- Understand the logic, not just the syntax. Examiners can tell if you have memorized code without understanding it.
- Review SQL commands. Many viva questions come from the MySQL portion of the syllabus.
- Practice explaining output. You may be asked to trace through your code and predict the output step by step.
Go through these questions the night before your practical exam, and you will walk in feeling prepared.
Want to learn more?
Explore free chapter-wise notes with quizzes and code playground
Prefer watching over reading?
Subscribe for free.