Python Viva Questions and Answers for Students
A rapid-fire set of Python viva and oral exam questions with short, precise answers, grouped by topic so you can revise quickly before a practical exam.
QuizMaster TeamSeptember 29, 20269 min read
A viva (oral exam) tests whether you can explain what you did and why, quickly and clearly, not whether you can write a long essay. This page collects short, precise answers to the Python questions that come up most often in college viva and lab examinations. Read each answer, then try explaining it out loud in your own words before you move on.
Basics and data types
- What is Python? A high-level, interpreted, general-purpose programming language known for readable syntax and a large standard library.
- Is Python statically or dynamically typed? Dynamically typed: a variable's type is determined at runtime and can change, because a name is just a label bound to an object.
- What is the difference between a list and a tuple? Both are ordered sequences; a list is mutable (can be changed after creation) and a tuple is immutable (cannot).
- What is the difference between `is` and `==`?
==compares values for equality;ischecks whether two names refer to the exact same object in memory. - What does `type()` do? Returns the type of an object, for example
type(5)gives<class 'int'>. - Why is Python called an interpreted language? Code is executed line by line by the Python interpreter rather than being compiled to machine code ahead of time (though it is compiled to bytecode internally).
Operators and control flow
- What is floor division? The
//operator divides and rounds the result down to the nearest whole number, e.g.7 // 2is 3. - What is the difference between `break` and `continue`?
breakexits the loop entirely;continueskips the rest of the current iteration and moves to the next one. - What does the `range()` function do? Generates a sequence of numbers, commonly used to control the number of iterations in a
forloop. - What is a nested loop? A loop placed inside another loop, often used to work through two-dimensional data such as rows and columns.
Functions and scope
- What is a function in Python? A named, reusable block of code defined with
def, which can accept parameters and return a value. - What is the difference between a parameter and an argument? A parameter is the name listed in a function's definition; an argument is the actual value passed in when the function is called.
- What is a default argument? A parameter that takes a preset value if the caller does not supply one, for example
def greet(name="friend"). - What does `return` do, and what happens without it?
returnsends a value back to the caller and ends the function. Without areturnstatement, a function returnsNone. - What is variable scope? Where a variable can be accessed from. A variable created inside a function is local to that function unless declared
global. - What is a lambda function? A small, unnamed function defined in a single expression, typically used for short throwaway logic such as a sort key.
Collections: lists, dictionaries, sets
- How do you add an item to a list? With
.append(item)to add one item at the end, or.extend(iterable)to add several. - What is a dictionary? An unordered (by lookup, though insertion order is preserved) collection of key-value pairs, accessed by key rather than by position.
- How do you check if a key exists in a dictionary? With
key in dictionary, which returns True or False. - What is a set used for? Storing unique values and performing fast membership tests; duplicates are automatically removed.
- What is a list comprehension? A compact way to build a list from an iterable in one line, for example
[x * 2 for x in range(5)].
Strings and errors
- Are strings mutable in Python? No. Any operation that appears to change a string actually creates a new one.
- What is string slicing? Extracting part of a string using
string[start:end], where the start index is included and the end index is excluded. - What is exception handling? Using
try/exceptblocks to catch and handle runtime errors gracefully instead of letting the program crash. - What is the difference between a syntax error and a runtime error? A syntax error means the code is not valid Python and will not run at all; a runtime error (exception) occurs while otherwise valid code is executing, such as dividing by zero.
Object-oriented Python
- What is a class? A blueprint for creating objects, describing the data (attributes) and behaviour (methods) they will have.
- What is `self`? The conventional name for the first parameter of an instance method, referring to the specific object the method was called on.
- What is `__init__`? A special method that runs automatically when a new object is created, typically used to set up initial attribute values.
- What is inheritance? A way for one class to reuse and extend the attributes and methods of another class.
How to prepare in the last hour
- Read each answer above once, then close the page and say it aloud from memory.
- Run a few short snippets yourself for the ideas you are least sure of, especially mutability and scope.
- Take the Python Basics quiz and the Python Functions quiz in practice mode, reading every explanation.
- Expect follow-up questions. If you say "a tuple is immutable," be ready to explain what that means with an example.
Key takeaways
- Vivas reward short, accurate, confidently spoken answers over long ones.
- Know the difference between == and is, list and tuple, and parameter and argument cold.
- Be ready to give a one-line example for every definition you state.
- Practise saying answers aloud, not just reading them.