Python Basic Viva Related Q&A
Python Basic Viva Related Q&A
1. Python Fundamentals
• Name a few popular Python libraries you’ve used and their purposes.
• What is a comprehension in Python? Provide examples for list, set, and dictionary
comprehensions.
5. Exception Handling
6. File Handling
8. Python Frameworks
• What are HTTP status codes, and when are they used?
• Be prepared to explain your past projects and the role you played.
1. Python Fundamentals
• A: Python is popular because it’s easy to learn, has a simple syntax, and supports multiple
programming pattern (OOP, functional, procedural). dynamically typed, platform-
independent, and having extensive libraries.
• A: A shallow copy copies the object but not the nested objects (references are shared). A
deep copy copies the object along with all its nested objects. Example: copy.copy() for
shallow, copy.deepcopy() for deep.
• A: Python uses automatic memory management through reference counting and a garbage
collector to reclaim unused memory.
Q: What is the difference between a list, tuple, and set?
• A: A list is mutable and ordered. A tuple is immutable and ordered. A set is unordered,
mutable, and stores unique elements.
Q: What is oops?
Oops that uses classes and objects to create reusable code that models real-world concepts
class Parent:
def greet(self):
class Child(Parent):
def greet(self):
obj = Child()
• A: Use private variables (_var or __var) and define getter and setter methods.
• A: Save a Python file as module_name.py and use import module_name to import it.
• A: os handles file and directory operations. sys deals with system-specific parameters and
functions.
• A: Use a requirements.txt file and manage dependencies with tools like pip or virtualenv.
Q: Name a few popular Python libraries you’ve used and their purposes.
• A: NumPy (numerical computations), Pandas (data analysis), Django (web development), and
Requests (HTTP requests).
• A: A dictionary is key-value based and unordered, while a list is index-based and ordered.
• A:
def gen():
yield 1
yield 2
**
1. Python Fundamentals
• A: Python is easy to learn, interpreted, dynamically typed, and has vast libraries. It’s popular
due to simplicity and versatility.
• A: Shallow copy copies references; deepcopy copies the entire object, including nested
ones.
• A: Python uses reference counting and garbage collection for memory management.
• A: List is ordered and mutable, tuple is ordered and immutable, set is unordered and stores
unique elements.
• A: Mutable (list) can be changed, immutable (tuple) cannot be changed after creation.
class Child(Parent):
def greet(self):
Q: Name a few popular Python libraries you’ve used and their purposes.
5. Exception Handling
6. File Handling
• A: Binary files store raw data, text files store human-readable text.
@decorator
def func():
pass
• A: Multithreading shares memory space, multiprocessing uses separate memory for each
process.
data = f.read()
8. Python Frameworks
• A: Django is full-stack, includes many built-in features. Flask is minimal and more flexible.
• A: WSGI is a specification for web servers and Python web apps to communicate.
Q: What are HTTP status codes, and when are they used?
• A: HTTP status codes indicate the outcome of a request, e.g., 200 OK, 404 Not Found.
• A: ORM (Object-Relational Mapper) allows interaction with databases using Python objects.
• A: unittest, pytest.
• A: Both are testing frameworks. unittest is built-in, pytest offers advanced features and
flexibility.
• A: Docker creates containerized environments for running Python apps consistently across
platforms.
Q: How do you manage dependencies in a Python project?
• A: Use tools like Docker, CI/CD pipelines, or platforms like AWS or Heroku.
• A:
python
Copy code
def reverse_string(s):
return s[::-1]
• A:
python
Copy code
def is_palindrome(s):
return s == s[::-1]
• A:
python
Copy code
• A:
python
Copy code
class Singleton:
_instance = None
def __new__(cls):
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance