Important Computer Science Class 12 Viva Voce Questions

1. Which language translator is used by Python? Python uses an Interpreter. An interpreter reads the code line by line, understands it, and executes it immediately. Unlike a compiler (which converts the entire code to machine language first), the interpreter does not create an executable file. Example: When you type print(“Hello”) in Python IDLE, it runs instantly. Easy to remember: “Interpreter = line-by-line teacher – reads, explains, and runs at the same time”

2. What are the built-in types available in Python? Python has these main built-in data types ready to use:

  • Numbers: int (whole numbers like 5), float (decimal like 3.14), complex (like 3+4j)
  • Strings: text like “Hello Python”
  • Lists: changeable ordered collection like [1, 2, “three”]
  • Tuples: unchangeable ordered collection like (1, 2, “three”)
  • Dictionaries: key-value pairs like {“name”: “Rahul”, “age”: 17}

Easy to remember: “Python’s 5 best friends: Numbers, Strings, Lists, Tuples, Dictionaries”

3. How does the Python interpreter interpret the code? The Python interpreter reads and executes the code line by line. It takes one line, understands it, runs it, and moves to the next line. If there is an error in any line, it stops there and shows the error message. This is different from compilers that check the entire code first.

Easy to remember: “Line-by-line reading, understanding, and running – that’s Python’s style”

4. Name a few mutable data types of Python. Mutable means: can be changed after creation. Main examples:

  • Lists – you can add, remove, or change items
  • Sets – you can add or remove items (no order)
  • Dictionaries – you can change, add, or remove key-value pairs

Easy to remember: “Mutable = mood swing friends – Lists, Sets, Dictionaries”

5. Name a few immutable data types of Python. Immutable means: cannot be changed once created. Main examples:

  • Strings – “Hello” cannot be modified
  • Tuples – (1, 2, 3) is fixed
  • Numeric types – int, float, complex

Easy to remember: “Immutable = strict teachers – Strings, Tuples, Numbers”

6. Name ordered and unordered data types of Python.

  • Ordered (maintain order, can access by index): String, List, Tuple Example: First item is always at index 0
  • Unordered (no guaranteed order): Set, Dictionary (Note: From Python 3.7, Dictionary keeps insertion order but it’s not guaranteed in definition)

Easy to remember: “Ordered = standing in line – String, List, Tuple; Unordered = crowd – Set, Dictionary”

7. What is the significance of a pass statement in Python? pass is a do-nothing statement. It is used when Python syntax requires a statement (like inside if, for, def), but you don’t want to write any code yet. Without pass, you get a syntax error because Python expects something in the block.

Example: if x > 10: pass # do nothing for now else: print(“Small”)

Easy to remember: “pass = keep quiet, do nothing – just placeholder”

8. What is slicing in Python? Slicing means extracting a part of a sequence (string, list, tuple). Format: sequence[start:stop:step]

  • start: where to begin (default 0)
  • stop: where to end (stop is not included)
  • step: jump size (default 1, -1 for reverse)

Examples: l = [10, 20, 30, 40, 50] l[1:4] → [20, 30, 40] l[::2] → [10, 30, 50] (every second) l[::-1] → [50, 40, 30, 20, 10] (reverse)

Easy to remember: “Slicing = cutting a piece of bread – start to stop, step size”

9. What are comments in Python? Comments are non-executable text in the code. Python completely ignores them. They are used to explain the code, why it is written, what it does, or to add notes for future reading.

Types:

  • Single-line: starts with # – # This is a comment
  • Multi-line: uses triple quotes – “”” This is multi-line comment “””

Easy to remember: “Comments = code diary – computer ignores, humans read”

10. What do you mean by forward and backward indexing?

  • Forward indexing: counting from left to right, starts at 0. Example: s = “Python” → s[0] = ‘P’, s[1] = ‘y’, s[5] = ‘n’
  • Backward indexing: counting from right to left, starts at -1. Example: s[-1] = ‘n’, s[-2] = ‘o’, s[-6] = ‘P’

Easy to remember: “Forward = normal 0 to end, Backward = reverse -1 to start”

11. How to print list l in reverse order in a single line statement? print(l[::-1])

This is slicing: empty start & stop means whole list, step -1 means reverse.

Easy to remember: “[::-1] = magic reverse trick”

12. Python string can be converted into integer or float? Yes – but only if the string contains only numbers (no letters or spaces). Examples: int(“123”) → 123 float(“45.67”) → 45.67

If there are letters → ValueError.

Easy to remember: “Only number string → int() or float() works”

13. What do you mean by typecasting in Python? Typecasting = changing one data type to another.

Two types:

  • Implicit (automatic by Python): safe conversion Example: 10 + 5.5 → 15.5 (int becomes float)
  • Explicit (done by programmer): using functions Example: int(“45”), float(10), str(100)

Easy to remember: “Typecasting = changing clothes of data – implicit automatic, explicit manual”

14. What is the difference between / and //?

  • / (normal division): always returns float (decimal result) 10 / 3 → 3.3333333333333335
  • // (floor division): returns integer (removes decimal, gives lower whole number) 10 // 3 → 3

Easy to remember: “/ = full answer with decimal, // = floor means lower whole number”

15. How to check the variables stored in same object in Python? Use id() function – it returns the memory address of the object.

Example: a = 10 b = 10 print(id(a) == id(b)) → True (same object)

Easy to remember: “id() = house address – same address means same object”

16. What are the parameters of print() function? Explain. print() has three main parameters:

  • message (or objects): what to print – first argument(s)
  • sep (separator): what to put between multiple items – default is space (‘ ‘) Example: print(“Hello”, “World”, sep=”—“) → Hello—World
  • end: what to put after printing – default is new line (‘\n’) Example: print(“Hello”, end=” “) → next print on same line

Easy to remember: “message = what to say, sep = between words, end = at the end”

17. What is the significance of ‘else’ in loops in Python? The else block in a loop runs only when the loop finishes normally (without break).

  • In while loop: runs when condition becomes False
  • In for loop: runs when all items are finished

Example: for i in range(5): print(i) else: print(“Loop completed”)

If break happens → else does not run.

Easy to remember: “else in loop = loop completed without break → party time”

18. Divya is learning Python. She wants to know the version of Python using Python programming statements. Please help her to accomplish her task. Code: import sys print(sys.version)

or simply import sys sys.version

This shows the full Python version info (like 3.12.1).

Easy to remember: “sys = system info, sys.version = Python version check”

19. How to remove the last element from a list? Two easy ways:

  • l.pop() → removes and returns the last element
  • del l[-1] → deletes the last element (no return)

Easy to remember: “pop = remove last and show it, del[-1] = delete last silently”

20. What is the difference between append() and extend() methods?

  • append(item): adds one item (even if it’s a list) to the end. Example: l = [1,2]; l.append([3,4]) → [1,2,[3,4]]
  • extend(iterable): adds each item separately from a list/tuple/etc. Example: l = [1,2]; l.extend([3,4]) → [1,2,3,4]

Easy to remember: “append = add one thing (even a box), extend = open box and add everything inside”

21. Consider the statement: L = [11,22,33,[45,67]], what will be the output of L[-2+1]? -2 + 1 = -1 L[-1] → last element → [45,67]

Easy to remember: “-2 + 1 = -1 → last item”

22. What is tuple unpacking? Tuple unpacking = assigning tuple values to separate variables in one line.

Example: t = (10, 20, 30) a, b, c = t print(a) → 10, b → 20, c → 30

Easy to remember: “Tuple unpacking = opening a gift box and putting items in separate hands”

23. What are the two ways to insert an element into dictionary?

  • Way 1: Direct assignment d = {1:’A’, 2:’B’} d[3] = ‘C’ → {1:’A’, 2:’B’, 3:’C’}
  • Way 2: Using setdefault() (does not overwrite if key exists) d.setdefault(3, ‘C’)

Easy to remember: “Direct d[key] = value or setdefault – both add new pair”

24. Samira wants to remove an element by value. Suggest her a function name to accomplish her task. l.remove(value)

Removes the first occurrence of the value. Example: l = [10, 20, 30, 20] → l.remove(20) → [10, 30, 20]

Easy to remember: “remove = delete by value”

25. How to remove all elements of a list? Two ways:

  • l.clear() → removes all elements, list becomes empty but object remains
  • del l[:] → removes all elements (list stays but empty)

Easy to remember: “clear = clean inside, del[:] = delete contents”

26. How del is different from clear?

  • l.clear() → empties the list, but the list object still exists Example: l = [1,2,3] → l.clear() → l = []
  • del l → deletes the entire list object (name disappears) del l[:] → only deletes contents, list name remains

Easy to remember: “clear = clean inside, del = destroy the whole thing”

27. What is a function? A function is a small, reusable block of code that performs a specific task. It can take input (parameters), do work, and return output.

Example: def add(a, b): return a + b

Easy to remember: “Function = helpful assistant – does one job repeatedly”

28. Does every Python program must return a value? No – not every function or program must return a value. Many functions just perform actions (like printing) and return nothing (implicitly return None).

Easy to remember: “Return is optional – many functions just do work”

29. What are the parts of a function? Three main parts:

  • Function header: starts with def def add(a, b):
  • Function body: indented block of instructions return a + b
  • Function call: using the function result = add(5, 3)

Easy to remember: “Header = name + params, Body = work, Call = use it”

30. What are the needs of function in the Python program? Functions are needed because:

  • Make program easy to manage (break into small parts)
  • Reduce program size
  • Avoid repeated code
  • Reduce confusion/ambiguity
  • Make code more readable and understandable

Easy to remember: “Functions = small packets – easy, short, no repeat, clear”

31. How to call your function through Python interactive mode?

  1. Save your program in a file (e.g., myfunc.py)
  2. In IDLE: Run → Run Module or press F5
  3. Interactive mode shows RESTART message
  4. Type function call: myfunc(10, 20)
  5. Press Enter, give input if needed

Easy to remember: “Save → F5 → RESTART → type function( values )”

32. What are void functions? Explain with example? Void functions are functions that do not return any value. They perform actions (like printing) but have no return statement (or return None).

Example: def greet(): print(“Hello, how are you?”)

greet() → prints message, returns nothing (None)

Easy to remember: “Void = empty return – just does work, gives nothing back”

33. Observe the following lines of code and identify function definition or function caller statement:

  • myfun(“TutorialAICSIP”,2020) → function caller (positional arguments – order matters)
  • myfun(name=”TutorialAICSIP”,year=2020) → function caller (keyword arguments – name given)
  • def myfun(name, year=2020) → function definition (with default argument)
  • myfun(name=”TutorialAICSIP”,year) → wrong caller (error because year needs value)

Easy to remember: “def = create, no def = call/use”

34. What are the physical line and logical line structure in Python program?

  • Physical line: one line as you see in the file – ends with EOL (End Of Line) character
  • Logical line: one complete statement that Python understands – may end with space, tab, or comment

Example: print(“Hello”) ← one physical and one logical line

Easy to remember: “Physical = what you see, Logical = what Python understands”

35. What is indentation? Explain its importance in two lines. Indentation means adding spaces/tabs at the beginning of lines. In Python, it defines code blocks, makes code readable, and organizes blocks properly.

Easy to remember: “Indentation = Python’s rule – wrong spaces = angry error”

36. What is a top-level statement in Python? Top-level statements are lines not indented inside any block (if, for, def, etc.). They run at the main level. main is also a top-level statement (when file is run directly).

Easy to remember: “Top-level = no indent – main level lines”

37. What are the comments? Explain the role of comments in the Python programs? Comments are non-executable text – Python ignores them completely. Role: explain code, note why written, add details for future reading.

Types:

  • Single-line: starts with #
  • Multi-line: triple quotes

Easy to remember: “Comments = code notes – computer skips, we read”

38. Does Python program functions contain multiple return statements and return multiple values? Yes – functions can have multiple return statements (first one reached stops the function). Multiple values: return a, b, c → returns as tuple

Example: def calc(x): return x2, x3

Easy to remember: “Multiple return = multiple doors, multiple values = return a, b, c”

39. What do you mean by fruitful and non-fruitful functions in Python?

  • Fruitful functions: return a value Example: def add(a,b): return a+b
  • Non-fruitful functions: do not return value (return None) Example: def greet(): print(“Hello”)

Easy to remember: “Fruitful = gives fruit (return), Non-fruitful = just work”

40. Which three types of functions supported by Python? Python supports three types:

  • Built-in Functions (ready-made): print(), len(), int(), range()
  • Functions defined in modules: math.sqrt(), random.randint()
  • User-defined functions: we create with def

Easy to remember: “Built-in = ready, Module = packaged, User = our creation”

41. What are parameters and arguments in Python programs?

  • Parameters: variables in function definition (placeholders) def add(a, b): ← a, b are parameters
  • Arguments: actual values given when calling add(5, 3) ← 5, 3 are arguments

Easy to remember: “Parameters = placeholders in definition, Arguments = real values when calling”

42. Which types of arguments supported by Python? Python supports four main types:

  • Positional Arguments: match by position/order def add(a, b): add(5, 3)
  • Default Arguments: have default value (right to left) def greet(name=”Guest”):
  • Keyword Arguments: give by name greet(name=”Rahul”)
  • Variable Length Arguments: *args (tuple) or **kwargs (dictionary) for many values

Easy to remember: “Positional = order, Default = backup, Keyword = by name, Variable = as many as you want”

43. What are the rules you should follow while combining different types of arguments? Rules for mixing:

  • Positional arguments must come first
  • Then keyword arguments
  • Keyword arguments preferably from required parameters
  • No argument value can be given more than once

Correct: add(5, b=10) Wrong: add(b=10, 5)

Easy to remember: “First position, then name – no repeat”

44. What do you mean by Python variable scope? Scope means: where the variable is visible and can be used. Python has two main scopes:

  • Local Scope: inside function
  • Global Scope: outside function (whole program)

Easy to remember: “Scope = visibility area – local inside room, global everywhere”

45. What is the local and global scope variable?

  • Local scope variable: declared inside function – only available inside that function
  • Global scope variable: declared at top level – available everywhere in program

Example: x = 10 ← global def func(): y = 20 ← local

Easy to remember: “Local = function’s own toy, Global = everyone’s toy”

46. What is the full form of LEGB? Explain in detail. LEGB = Local – Enclosing – Global – Built-in

Python searches for variable in this order:

  • Local: first check inside current function
  • Enclosing: if nested function → check outer function
  • Global: then top-level program
  • Built-in: last – Python’s own names (print, len, etc.)

Easy to remember: “LEGB = look Local first, then Enclosing, Global, Built-in last”

47. What are mutable and immutable arguments/parameters in a function call?

  • Mutable arguments: list, dict, etc. – changes inside function affect original
  • Immutable arguments: int, string, tuple – changes inside create new object, original unchanged

Easy to remember: “Mutable = original changes, Immutable = new copy made”

48. What are modules in Python? A module is a .py file containing functions, classes, variables, etc. Large programs are divided into modules for reuse. Modules create libraries.

Example: math module has sqrt(), sin(), etc.

Easy to remember: “Module = toolbox – separate file with tools, import when needed”

49. Name few commonly used libraries in Python.

  • Standard library (comes with Python): math, random, sys, os
  • NumPy Library: for arrays and math
  • Matplotlib: for graphs/plots
  • SciPy: for scientific calculations

Easy to remember: “Standard = built-in, NumPy-Matplotlib-SciPy = science tools”

50. What do you mean docstrings in Python? Docstrings are triple-quoted strings written right after function/module/class definition. They explain: author, purpose, how to use, parameters, return value, etc. Accessed using help() function.

Example: def add(a, b): “””Adds two numbers””” return a + b

Easy to remember: “Docstring = function’s introduction – help() reads it”

51. Is there any difference between docstrings and comments? Both ignored by interpreter, but difference:

  • Comments: just notes, not accessible by help()
  • Docstrings: documentation, accessible via help() or doc

Easy to remember: “Comments = private notes, Docstrings = public info for help()”

52. What is the use of dir() function? dir() shows all available methods, attributes, and symbols in a module or object.

Example: import math print(dir(math)) → shows sin, cos, sqrt, etc.

Easy to remember: “dir() = show everything inside – like opening the toolbox”

53. What are the two ways to import modules?

  • import modulename: import whole module – math.sqrt()
  • from module import object: import only needed part – from math import sqrt

Easy to remember: “import full box, from = take only one tool”

54. What is a file? A file is a stream of bytes stored on secondary storage (hard disk) with a name and extension (like .txt, .py).

Easy to remember: “File = named box on disk with extension”

55. What are the different modes of opening a file? Modes:

  • r (read): read only
  • w (write): write (overwrite)
  • a (append): add at end
  • r+ (read + write)
  • w+ (write + read)
  • a+ (append + read)
  • rb, wb, ab (binary modes)
  • rb+, wb+, ab+

Easy to remember: “r = read, w = write/overwrite, a = add, + = both”

56. If no mode is specified in open() function, which mode will be considered? Default mode: r (read only)

Easy to remember: “No mode = read mode (r)”

57. What is the difference between “w” and “a” mode?

  • w mode: overwrites the file – old content deleted
  • a mode: appends – old content remains, new added at end

Easy to remember: “w = wipe and write, a = add to existing”

58. What is the difference between readline() and readlines() function?

  • readline(): reads one line and returns as string
  • readlines(): reads all lines and returns as list of strings

Easy to remember: “readline = one line string, readlines = all lines in list”

59. Parth wants to read only n number of characters from a text file. Suggest him a function to accomplish his task. f.read(n)

Reads first n characters from the file.

Easy to remember: “read(n) = read only n letters”

60. Nakshatra wants to count no. of words from the text file. Suggest her code to accomplish a task. Code: f = open(“one.txt”) w = f.read().split() # split on spaces → list of words c = 0 for i in w: c += 1 print(c)

Short version: print(len(open(“one.txt”).read().split()))

Easy to remember: “read → split → count/len = word count”

61. What are the two different types of text files?

  • Plain text or regular text files: normal .txt files
  • Delimited text files or separated text files: data separated by delimiter (like CSV, TSV)

Easy to remember: “Plain = simple text, Delimited = separated data”

62. What are full forms of: a) csv b) tsv

  • csv: Comma Separated Values
  • tsv: Tab Separated Values

Easy to remember: “CSV = comma separated, TSV = tab separated”

63. Are CSV files and Text Files same? They are same in storage (both text), but CSV files have data separated by comma (or other delimiter).

Easy to remember: “CSV = special text file with commas”

64. What are the different valid delimiters? Default: comma (,) Others: tab (\t), colon (:), semicolon (;)

Easy to remember: “Common delimiters: , \t : ;”

65. What is pickling? Pickling = converting Python object (list, dict, etc.) into byte stream and writing to binary file.

Easy to remember: “Pickling = turn object into pickle (bytes) for saving”

66. What is unpickling? Unpickling = converting byte stream from binary file back into Python object.

Easy to remember: “Unpickling = open pickle and get object back”

67. Which module is required to handle binary files? pickle module

Easy to remember: “pickle = binary file helper”

68. Name the functions used to read and write data into binary files.

  • pickle.dump(object, file_handle) → write
  • pickle.load(file_object) → read

Easy to remember: “dump = put inside, load = take out”

69. Which error is reported while reading the file binary file? ran out of input (EOFError) – when no more data left in file

Easy to remember: “ran out of input = no data left”

70. How to avoid reading file errors in binary file? Use exception handling with try and except blocks.

Example: try: data = pickle.load(f) except EOFError: print(“File ended”)

Easy to remember: “try-except = safety net for errors”

71. What is the significance of tell() and seek() functions?

  • tell(): returns current file pointer position (where we are reading/writing)
  • seek(offset, from_where): moves pointer to new position

Easy to remember: “tell = where am I?, seek = go to this position”

72. What is the default value of offset for seek function? 0 (start of file)

Easy to remember: “Default offset = 0 – beginning”

73. What is offset in the syntax of seek function? Offset = number of bytes to move the file pointer (forward or backward).

Easy to remember: “Offset = distance in bytes”

74. Nimesh is working on a stack. He started deleting elements and removed all the elements from the stack. Name this situation. Stack underflow – trying to pop from empty stack.

Easy to remember: “Underflow = below empty – nothing left to remove”

75. What are the operations can be performed on the stack?

  • Push: add element at top
  • Pop: remove element from top
  • Peek (or Peep): see top element without removing

Easy to remember: “Push = put on top, Pop = take from top, Peek = look at top”

76. Which principle is followed by stack? LIFO (Last In First Out) – last added item comes out first.

Easy to remember: “LIFO = last in first out – like stack of plates”

77. Name any three applications of stack.

  • Call history on mobile (back button)
  • Browser history (back button)
  • Undo and redo commands (Ctrl+Z)
  • CD/DVD tracks
  • Books on table (top book removed first)

Easy to remember: “Stack = back button, undo, call history”

78. What is an exception in Python? An exception is an error or unusual condition during program execution that causes abnormal termination or crash.

Easy to remember: “Exception = sudden roadblock – program stops”

79. What do you mean by debugging? Debugging = finding and fixing errors (bugs) in the program.

Easy to remember: “Debugging = hunt and kill bugs”

80. Tell me the three basic types of errors that occur in Python.

  • Syntax Errors: writing mistakes (forgot colon)
  • Logical Errors: code runs but wrong result
  • Run-Time Errors: crash during execution (divide by zero)

Easy to remember: “Syntax = writing wrong, Logical = thinking wrong, Run-time = crash while running”

81. What is the significance of following keywords in Python for exception handling? assert, raise, try, except, finally, else

  • assert: checks condition – if false, raises AssertionError
  • raise: manually create/throw exception
  • try: block where error might happen
  • except: catch and handle specific exception
  • finally: always runs (error or no error)
  • else: runs if no exception in try block

Easy to remember: “try = risky area, except = catch, finally = always, else = no problem”

82. Name a few commonly exceptions occurs in Python.

  • SyntaxError: writing mistake
  • IndexError: wrong index
  • TypeError: wrong type
  • NameError: name not found
  • KeyError: key missing in dict
  • ValueError: wrong value
  • ZeroDivisionError: divide by zero

Easy to remember: “Index, Type, Name, Key, Value, Zero – common troublemakers”

83. Which exception occurs if the specified file does not exist in Python? FileNotFoundError

Easy to remember: “File not found = FileNotFoundError”

84. Differentiate between errors and exceptions?

  • Errors: usually stop program completely (like syntax error)
  • Exceptions: interrupt normal flow during runtime – can be handled (try-except)

Sometimes errors don’t stop but exceptions usually do unless handled.

Easy to remember: “Error = full stop, Exception = pause – can continue if handled”

85. What happens if an exception occurs in a try block and there is no matching except block? Python terminates the program immediately and shows/propagates the specific exception message.

Easy to remember: “No matching except = crash and show error”

All the best for your Class 12 Computer Science viva! Practice well – explain in your own words with examples. You’ve got this!

1 thought on “Important Computer Science Class 12 Viva Voce Questions”

Leave a Reply

Your email address will not be published. Required fields are marked *