Python VIVA
Python VIVA
Introduction to Python
Python is a high-level, interpreted, and general-purpose programming language with simple syntax,
making it easy to learn and use.
Features:
• Easy to read/write
• Object-oriented
• Text: str
• Boolean: bool
• Mapping: dict
• NoneType: None
• Case-sensitive
Typecasting is converting one data type into another (e.g., string to integer using int()).
List Methods: append(), insert(), pop(), remove(), clear(), sort(), reverse(), extend(), etc.
Set Methods: add(), remove(), discard(), union(), intersection(), difference(), clear(), etc.
A dictionary is a collection of unordered, mutable key-value pairs. Keys are unique and immutable.
Indexing is the method to access individual elements in sequences (like lists or strings) using their
position.
15. Explain the difference between if, elif, and else statements.
• while: Used when the condition must be true for looping to continue
A loop that never ends due to a condition that always evaluates to true.
Prevention: Ensure proper exit conditions or use break.
The return statement is used to send a result back to the caller of the function and exit the function.
Using open() function with modes like 'r' (read), and then using .read(), .readline() or .readlines()
methods.
Using try and except blocks to catch and handle errors during execution.
30. Explain encapsulation with an example. What is public, private, and protected?
Inheritance allows a class (child) to inherit properties/methods from another class (parent),
promoting code reuse.
32. What are the different types of inheritance in Python?
• Single
• Multiple
• Multilevel
• Hierarchical
• Hybrid
Polymorphism allows functions/methods to behave differently based on the context, such as same
method name behaving differently in different classes.
34. What is the difference between method overloading and method overriding?
• Overloading: Same method name with different parameters (not natively supported in
Python)
35. What is the difference between a class variable and an instance variable?
self refers to the current instance of the class and is used to access instance variables and methods.
38. What are regular expressions? Why are they used in Python?
Regular expressions (regex) are patterns used to match strings. Used for searching, validation, or
string manipulation.
39. How do you use the re module for pattern matching?
Using functions like match(), search(), findall(), and sub() provided by the re module.
6. Python Libraries
A powerful numerical computing library in Python. Used for handling large arrays, matrices, and
mathematical operations.
A Python library used for creating static, interactive, and animated plots and visualizations.
• NumPy Array: More efficient, faster, supports element-wise operations, used for numerical
data