100+ CBSE Class 12 Computer Science Practical Viva Questions & Answers 2025-26

Python Programming (Questions 1-40)
Basic Python Concepts
Q1. What is Python? A: Python is a high-level, interpreted, object-oriented programming language known for its simplicity and readability. It was created by Guido van Rossum in 1991.
Q2. What are the key features of Python? A: Easy to learn and read, interpreted language, dynamically typed, supports multiple programming paradigms, extensive standard library, platform independent, and supports integration with other languages.
Q3. What is the difference between compiler and interpreter? A: A compiler translates the entire program at once and creates an executable file, while an interpreter translates and executes code line by line. Python uses an interpreter.
Q4. What are Python identifiers? A: Identifiers are names given to variables, functions, classes, or other objects. They must start with a letter or underscore and contain only alphanumeric characters and underscores.
Q5. What are keywords in Python? A: Keywords are reserved words that have special meaning in Python (like if, else, for, while, def, class, etc.). They cannot be used as identifiers.
Q6. What is the difference between mutable and immutable data types? A: Mutable objects can be modified after creation (list, dictionary, set), while immutable objects cannot be changed once created (int, float, string, tuple).
Q7. What is the difference between list and tuple? A: Lists are mutable and use square brackets [], while tuples are immutable and use parentheses (). Lists are slower but more flexible than tuples.
Q8. What is a dictionary in Python? A: A dictionary is an unordered collection of key-value pairs enclosed in curly braces {}. Keys must be unique and immutable, while values can be of any type.
Q9. What is type casting in Python? A: Type casting is the conversion of one data type to another using functions like int(), float(), str(), list(), etc.
Q10. What is the difference between ‘==’ and ‘is’ operators? A: ‘==’ checks if values are equal, while ‘is’ checks if two variables point to the same object in memory (identity comparison).
Control Structures
Q11. What is the difference between break and continue statements? A: break exits the entire loop immediately, while continue skips the current iteration and moves to the next iteration of the loop.
Q12. What is the purpose of the pass statement? A: pass is a null statement that does nothing. It’s used as a placeholder where syntactically some code is required but you don’t want to execute anything.
Q13. What is the difference between while and for loop? A: while loop executes as long as a condition is true (condition-controlled), while for loop iterates over a sequence for a fixed number of times (count-controlled).
Q14. Can we use else with loops in Python? A: Yes, else can be used with loops. The else block executes when the loop completes normally without encountering a break statement.
Q15. What is nested loop? A: A nested loop is a loop inside another loop. The inner loop executes completely for each iteration of the outer loop.
Functions
Q16. What is a function in Python? A: A function is a reusable block of code that performs a specific task. It is defined using the def keyword and can accept parameters and return values.
Q17. What is the difference between parameters and arguments? A: Parameters are variables listed in the function definition, while arguments are actual values passed to the function when calling it.
Q18. What are default arguments? A: Default arguments are parameters that assume a default value if no argument is provided during function call. Example: def func(x=10).
Q19. What are keyword arguments? A: Keyword arguments are arguments passed to a function with their parameter names explicitly specified, allowing them to be passed in any order.
Q20. What is the return statement? A: The return statement exits a function and optionally passes back a value to the caller. A function without return returns None by default.
Q21. What is scope of a variable? A: Scope defines the region where a variable is accessible. Python has local scope (inside function) and global scope (outside all functions).
Q22. What is a lambda function? A: A lambda function is an anonymous function defined using the lambda keyword. It can have any number of parameters but only one expression. Syntax: lambda arguments: expression
Q23. What are built-in functions in Python? A: Built-in functions are predefined functions available in Python like print(), input(), len(), range(), type(), max(), min(), sum(), etc.
File Handling
Q24. What is file handling in Python? A: File handling allows reading from and writing to files. Python provides built-in functions to create, read, write, and manipulate files.
Q25. What are different file opening modes? A: ‘r’ (read), ‘w’ (write), ‘a’ (append), ‘r+’ (read and write), ‘w+’ (write and read), ‘a+’ (append and read), ‘rb’ (read binary), ‘wb’ (write binary).
Q26. What is the difference between write() and writelines()? A: write() writes a single string to the file, while writelines() writes a list of strings to the file without adding line breaks automatically.
Q27. What is the difference between read(), readline(), and readlines()? A: read() reads entire file, readline() reads one line at a time, readlines() reads all lines and returns them as a list.
Q28. Why should we close a file after opening it? A: Closing a file releases system resources, ensures all data is written to disk, and prevents data corruption. It’s good practice to use the with statement for automatic closing.
Q29. What is the with statement in file handling? A: The with statement provides automatic resource management. It automatically closes the file even if an exception occurs. Syntax: with open(‘file.txt’, ‘r’) as f:
Q30. What is the difference between text and binary files? A: Text files store data as human-readable characters (txt, csv), while binary files store data in binary format (images, audio, video, executable files).
Data Structures
Q31. How do you create an empty list? A: Using empty square brackets: mylist = [] or using list() constructor: mylist = list()
Q32. What is list slicing? A: List slicing extracts a portion of a list using the syntax list[start:stop:step]. Example: mylist[1:5] returns elements from index 1 to 4.
Q33. What are list methods? A: Common list methods include append(), extend(), insert(), remove(), pop(), clear(), index(), count(), sort(), reverse(), copy().
Q34. What is the difference between append() and extend()? A: append() adds a single element at the end of the list, while extend() adds multiple elements from an iterable to the end of the list.
Q35. How do you create a dictionary? A: Using curly braces with key-value pairs: mydict = {‘key1’: ‘value1’, ‘key2’: ‘value2’} or using dict() constructor.
Q36. What are dictionary methods? A: Common methods include keys(), values(), items(), get(), update(), pop(), popitem(), clear(), copy().
Q37. What is the difference between del and pop() for removing elements? A: del removes an element by key/index and returns nothing, while pop() removes and returns the element. pop() also allows a default value if key is not found.
Q38. What is a set in Python? A: A set is an unordered collection of unique elements enclosed in curly braces {}. It doesn’t allow duplicate values and supports mathematical set operations.
Q39. What are set operations? A: Union (|), intersection (&), difference (-), symmetric difference (^), subset (<=), superset (>=), and methods like add(), remove(), discard().
Q40. What is the difference between remove() and discard() in sets? A: remove() raises an error if the element is not found, while discard() does nothing if the element doesn’t exist.
Object-Oriented Programming (Questions 41-60)
Q41. What is Object-Oriented Programming (OOP)? A: OOP is a programming paradigm based on the concept of objects that contain data (attributes) and code (methods). It focuses on creating reusable and modular code.
Q42. What are the main principles of OOP? A: The four main principles are Encapsulation, Inheritance, Polymorphism, and Abstraction.
Q43. What is a class? A: A class is a blueprint or template for creating objects. It defines attributes and methods that the objects will have.
Q44. What is an object? A: An object is an instance of a class. It is a real-world entity with state (attributes) and behavior (methods).
Q45. What is the init method? A: init is a constructor method that is automatically called when an object is created. It initializes the object’s attributes.
Q46. What is self in Python? A: self is a reference to the current instance of the class. It is used to access variables and methods of the class within class methods.
Q47. What is encapsulation? A: Encapsulation is the bundling of data and methods within a class and restricting direct access to some components using access modifiers (public, private, protected).
Q48. What is inheritance? A: Inheritance is a mechanism where a new class (child/derived class) inherits properties and methods from an existing class (parent/base class).
Q49. What are the types of inheritance? A: Single inheritance, multiple inheritance, multilevel inheritance, hierarchical inheritance, and hybrid inheritance.
Q50. What is method overriding? A: Method overriding occurs when a child class provides a specific implementation of a method that is already defined in its parent class.
Q51. What is polymorphism? A: Polymorphism means “many forms.” It allows methods to do different things based on the object calling them (method overloading and overriding).
Q52. What is the difference between class variables and instance variables? A: Class variables are shared by all instances of a class, while instance variables are unique to each object and defined within init using self.
Q53. What is abstraction? A: Abstraction hides complex implementation details and shows only essential features. In Python, it’s implemented using abstract classes and methods.
Q54. What is a constructor? A: A constructor is a special method (init) that initializes an object when it is created. It sets initial values for object attributes.
Q55. What is a destructor? A: A destructor is a special method (del) called when an object is about to be destroyed. It’s used for cleanup operations.
Q56. Can we have multiple constructors in Python? A: No, Python doesn’t support multiple constructors. However, we can achieve similar functionality using default arguments or *args and **kwargs.
Q57. What is data hiding? A: Data hiding is an aspect of encapsulation where class members are made private (using __ prefix) to restrict direct access from outside the class.
Q58. What is the super() function? A: super() is used to call methods from the parent class. It’s commonly used to call the parent class’s init method in the child class.
Q59. What are class methods and static methods? A: Class methods (decorated with @classmethod) receive the class as the first argument. Static methods (decorated with @staticmethod) don’t receive class or instance automatically.
Q60. What is the difference between public, private, and protected members? A: Public members (no prefix) are accessible everywhere, protected members (single _) are accessible within class and subclasses, private members (double __) are accessible only within the class.
Data Structure Using Python (Questions 61-75)
Q61. What is a stack? A: A stack is a linear data structure that follows LIFO (Last In First Out) principle. Elements are added and removed from the same end called the top.
Q62. What are the basic operations on a stack? A: Push (add element), Pop (remove element), Peek/Top (view top element), isEmpty (check if stack is empty), and Size (get number of elements).
Q63. How can we implement a stack in Python? A: Using a list with append() for push and pop() for pop operations, or using collections.deque, or creating a custom Stack class.
Q64. What is a queue? A: A queue is a linear data structure that follows FIFO (First In First Out) principle. Elements are added at the rear and removed from the front.
Q65. What are the basic operations on a queue? A: Enqueue (add element at rear), Dequeue (remove element from front), Front (view front element), isEmpty, and Size.
Q66. What is the difference between stack and queue? A: Stack follows LIFO (Last In First Out), while queue follows FIFO (First In First Out). Stack has one end for operations, queue has two ends.
Q67. What is a linked list? A: A linked list is a linear data structure where elements (nodes) are stored in non-contiguous memory locations. Each node contains data and a reference to the next node.
Q68. What are the types of linked lists? A: Singly linked list (one-way), doubly linked list (two-way), and circular linked list (last node points to first).
Q69. What are the advantages of linked lists over arrays? A: Dynamic size, efficient insertions/deletions, no memory wastage, and easy to implement other data structures like stacks and queues.
Q70. What is recursion? A: Recursion is a programming technique where a function calls itself to solve a problem by breaking it into smaller sub-problems.
Q71. What are the components of a recursive function? A: Base case (stopping condition) and recursive case (function calling itself with modified parameters).
Q72. What is the difference between iteration and recursion? A: Iteration uses loops and is generally faster with less memory overhead. Recursion calls itself and uses more memory (call stack) but can make code more elegant for certain problems.
Q73. What is binary search? A: Binary search is an efficient searching algorithm for sorted arrays. It repeatedly divides the search interval in half, with time complexity O(log n).
Q74. What is the difference between linear search and binary search? A: Linear search checks each element sequentially (O(n)), works on unsorted data. Binary search divides array in half (O(log n)), requires sorted data.
Q75. What are sorting algorithms you’ve studied? A: Bubble sort, selection sort, insertion sort are commonly taught. They compare and swap elements to arrange them in order.
Database Management and SQL (Questions 76-95)
Q76. What is a database? A: A database is an organized collection of structured data stored electronically. It allows efficient storage, retrieval, and management of information.
Q77. What is DBMS? A: Database Management System is software that manages databases. It provides an interface to perform operations like insertion, deletion, modification, and retrieval of data.
Q78. What is SQL? A: SQL (Structured Query Language) is a standard language used to communicate with databases for storing, manipulating, and retrieving data.
Q79. What are the types of SQL commands? A: DDL (Data Definition Language), DML (Data Manipulation Language), DCL (Data Control Language), TCL (Transaction Control Language), and DQL (Data Query Language).
Q80. What is the difference between DDL and DML? A: DDL defines database structure (CREATE, ALTER, DROP), while DML manipulates data (INSERT, UPDATE, DELETE, SELECT).
Q81. What is a primary key? A: A primary key is a unique identifier for each record in a table. It cannot contain NULL values and must be unique for each row.
Q82. What is a foreign key? A: A foreign key is a field in one table that refers to the primary key in another table. It establishes a relationship between two tables.
Q83. What is the difference between WHERE and HAVING clauses? A: WHERE filters rows before grouping, while HAVING filters groups after GROUP BY operation. HAVING is used with aggregate functions.
Q84. What are aggregate functions in SQL? A: Functions that perform calculations on a set of values and return a single value: COUNT(), SUM(), AVG(), MAX(), MIN().
Q85. What is the difference between DELETE and TRUNCATE? A: DELETE removes specific rows and can be rolled back, while TRUNCATE removes all rows, is faster, cannot be rolled back, and resets auto-increment counters.
Q86. What is the difference between CHAR and VARCHAR? A: CHAR is fixed-length character data type, while VARCHAR is variable-length. CHAR pads with spaces, VARCHAR stores only actual data length.
Q87. What is a constraint in SQL? A: Constraints are rules enforced on data columns to ensure data accuracy and integrity: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT.
Q88. What is the ORDER BY clause? A: ORDER BY sorts query results in ascending (ASC) or descending (DESC) order based on one or more columns.
Q89. What is the GROUP BY clause? A: GROUP BY groups rows with same values in specified columns and is typically used with aggregate functions to perform calculations on each group.
Q90. What are different types of joins? A: INNER JOIN (matching rows), LEFT JOIN (all left table rows), RIGHT JOIN (all right table rows), FULL OUTER JOIN (all rows from both tables), CROSS JOIN (cartesian product).
Q91. What is the difference between UNION and UNION ALL? A: UNION combines results from multiple SELECT statements and removes duplicates, while UNION ALL includes all rows including duplicates.
Q92. What is normalization? A: Normalization is organizing data to reduce redundancy and dependency. It divides large tables into smaller ones and defines relationships between them.
Q93. What are different normal forms? A: 1NF (atomic values, no repeating groups), 2NF (no partial dependency), 3NF (no transitive dependency), BCNF (Boyce-Codd Normal Form).
Q94. What is the difference between LIKE and IN operators? A: LIKE is used for pattern matching with wildcards (% and _), while IN checks if a value exists in a specified list of values.
Q95. What are wildcard characters in SQL? A: % (matches any sequence of characters), _ (matches single character), [] (matches any single character within brackets), [^] (matches any character not in brackets).
Python-MySQL Connectivity (Questions 96-110)
Q96. Which module is used for Python-MySQL connectivity? A: mysql.connector module is commonly used for connecting Python programs with MySQL database.
Q97. What are the steps to connect Python with MySQL? A: Import mysql.connector, establish connection using connect(), create cursor object, execute SQL queries, fetch results, commit changes, close cursor and connection.
Q98. What is a cursor in Python-MySQL connectivity? A: A cursor is an object that allows Python code to execute SQL queries and fetch results from the database.
Q99. What is the difference between commit() and rollback()? A: commit() saves all changes made in the current transaction permanently, while rollback() undoes all changes made in the current transaction.
Q100. What are fetchone(), fetchall(), and fetchmany()? A: fetchone() retrieves one row, fetchall() retrieves all rows, fetchmany(n) retrieves n rows from the query result set.
Q101. Write the syntax to establish MySQL connection in Python. A:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="username",
password="password",
database="database_name"
)
Q102. How do you execute a SELECT query in Python? A: Create a cursor, use cursor.execute(“SELECT * FROM table”), then fetch results using fetchone(), fetchall(), or fetchmany().
Q103. How do you handle exceptions in Python-MySQL connectivity? A: Use try-except blocks to catch mysql.connector.Error exceptions and handle database-related errors gracefully.
Q104. What is the purpose of close() method? A: close() method closes the cursor or connection, releasing database resources and freeing memory.
Q105. How do you prevent SQL injection in Python? A: Use parameterized queries with placeholders (%s) instead of string concatenation. Example: cursor.execute(“SELECT * FROM users WHERE id = %s”, (user_id,))
Q106. What is the difference between execute() and executemany()? A: execute() executes a single query, while executemany() executes the same query with multiple sets of parameters efficiently.
Q107. How do you check if a table exists in MySQL using Python? A: Execute “SHOW TABLES” query and check if the table name exists in the results, or use “SHOW TABLES LIKE ‘tablename'”.
Q108. What is rowcount in cursor object? A: rowcount is an attribute that returns the number of rows affected by the last execute() operation.
Q109. How do you insert data into MySQL table using Python? A: Use INSERT query with cursor.execute(), provide values using parameterized queries, and call mydb.commit() to save changes.
Q110. What is autocommit in MySQL connection? A: Autocommit automatically commits each SQL statement immediately. It can be enabled by setting autocommit=True in connection or using mydb.autocommit = True.
Project and General Questions (Questions 111-115)
Q111. Explain your Python project. A: Describe your project’s purpose, features, technologies used (Python, MySQL), key functions, database structure, and how different modules work together.
Q112. What challenges did you face while developing the project? A: Discuss technical challenges like database connectivity issues, error handling, data validation, user interface design, or any debugging experiences.
Q113. How did you ensure data validation in your project? A: Explain validation techniques like checking data types, range validation, format validation, handling empty inputs, and providing appropriate error messages.
Q114. What improvements can be made to your project? A: Suggest enhancements like adding GUI, implementing security features, adding more functionalities, improving error handling, or optimizing database queries.
Q115. Why did you choose Python for your project? A: Python is easy to learn, has extensive libraries, supports database connectivity, has clear syntax, is platform-independent, and is suitable for rapid development.
Tips for Practical Viva Success
- Understand Your Code: Be prepared to explain every line of your project code
- Know the Theory: Link practical implementations with theoretical concepts
- Practice SQL Queries: Be ready to write queries on the spot
- Database Structure: Know your table structures, relationships, and constraints
- Be Confident: Answer clearly and confidently, admit if you don’t know something
- Prepare Output: Know the expected outputs of your program for different inputs
- Error Handling: Be able to explain how you handle errors in your code
- Time Complexity: Understand the efficiency of algorithms you’ve used
- Alternative Approaches: Think about different ways to solve the same problem
- Stay Calm: Take a moment to think before answering questions
Conclusion
This comprehensive list covers essential topics for CBSE Class 12 Computer Science practical viva. Regular practice and thorough understanding of concepts will ensure success in your board exam. Focus on hands-on coding practice and connecting theoretical knowledge with practical implementation.
Good luck with your practical examination!
