Basic Python Viva Questions
1. What is Python?
Python is a high-level, interpreted, and object-oriented programming language used for web development, data science, AI, automation, and more.
2. Who developed Python?
Python was developed by Guido van Rossum in 1991.
3. Why is Python popular?
-
Easy to learn and read
-
Large standard library
-
Platform independent
-
Supports multiple programming paradigms
4. What are Python features?
-
Interpreted language
-
Dynamically typed
-
Object-oriented
-
Portable
-
Open-source
5. What is an interpreter?
An interpreter executes code line by line, making debugging easier.
Data Types & Variables
6. What are Python data types?
-
int
-
float
-
complex
-
str
-
list
-
tuple
-
set
-
dict
-
bool
7. What is a variable?
A variable is a name that stores data in memory.
Example:
8. Is Python dynamically typed?
Yes, Python does not require variable type declaration.
9. Difference between list and tuple?
| List | Tuple |
|---|---|
| Mutable | Immutable |
| Uses [] | Uses () |
| Slower | Faster |
10. What is a dictionary?
A dictionary stores data in key–value pairs.
Example:
Operators & Control Statements
11. Types of operators in Python?
-
Arithmetic
-
Relational
-
Logical
-
Assignment
-
Bitwise
-
Membership
-
Identity
12. What are control statements?
They control program flow:
-
if, elif, else
-
for loop
-
while loop
-
break, continue, pass
13. What is a loop?
A loop executes a block of code repeatedly.
Functions & Modules
14. What is a function?
A function is a reusable block of code.
Example:
15. What is a module?
A module is a file containing Python code (functions, variables).
Example:
16. What is a package?
A package is a collection of modules.
OOP in Python
17. What is OOP?
Object-Oriented Programming organizes code using objects and classes.
18. What is a class?
A class is a blueprint for creating objects.
19. What is an object?
An object is an instance of a class.
20. OOP principles?
-
Encapsulation
-
Inheritance
-
Polymorphism
-
Abstraction
File Handling & Exceptions
21. How to open a file in Python?
22. What is exception handling?
Handling runtime errors using:
23. What is finally block?
It executes whether an exception occurs or not.
Advanced & Miscellaneous
24. What is PEP 8?
PEP 8 is the Python style guide.
25. What is slicing?
Extracting part of a sequence.
Example:
26. What is lambda function?
A small anonymous function.
Example:
27. What is list comprehension?
A concise way to create lists.
Example:
28. What is virtual environment?
An isolated environment for Python projects.
29. What is NumPy?
NumPy is a library for numerical computations.
30. What is Pandas?
Pandas is used for data analysis and data manipulation.
31. What is indentation in Python?
Indentation defines blocks of code. Python uses indentation instead of braces {}.
32. What happens if indentation is wrong?
Python raises an IndentationError.
33. What is pass statement?
pass is a null statement used when no action is required.
34. What is break and continue?
-
breakexits the loop -
continueskips the current iteration
35. What is range() function?
Generates a sequence of numbers.
Example:
36. What is type casting?
Converting one data type into another.
Example:
37. Difference between is and ==?
-
==checks value equality -
ischecks memory location
38. What is None?
None represents absence of a value.
39. What is mutable and immutable?
-
Mutable: list, dict, set
-
Immutable: int, float, tuple, string
40. What is a namespace?
A namespace is a mapping of names to objects.
Functions & Arguments
41. Types of function arguments?
-
Positional
-
Keyword
-
Default
-
Variable-length (
*args,**kwargs)
42. What is recursion?
A function calling itself.
43. What is *args?
Used to pass multiple positional arguments.
44. What is **kwargs?
Used to pass multiple keyword arguments.
45. What is docstring?
A string that describes a function or module.
Example:
Strings & Collections
46. String methods in Python?
-
upper()
-
lower()
-
split()
-
replace()
-
strip()
47. What is slicing in list?
Extracting part of a list.
Example:
48. What is set?
An unordered collection of unique elements.
49. Why dictionary keys must be unique?
Keys act as identifiers for values.
50. Difference between shallow copy and deep copy?
-
Shallow copy: copies references
-
Deep copy: copies all objects
File Handling
51. File modes in Python?
-
r– read -
w– write -
a– append -
r+– read & write
52. What is with statement?
Used for automatic file closing.
53. How to read CSV file in Python?
Using csv or pandas module.
Exception Handling
54. Types of errors in Python?
-
Syntax Error
-
Runtime Error
-
Logical Error
55. What is raise keyword?
Used to create custom exceptions.
56. Multiple except blocks—why?
To handle different exceptions separately.
OOP – Advanced
57. What is constructor?
A special method __init__() used to initialize objects.
58. What is destructor?
__del__() method used to destroy objects.
59. What is method overloading?
Multiple methods with same name but different parameters
(Note: Python supports it using default arguments).
60. What is method overriding?
Child class redefining parent class method.
Advanced Python Concepts
61. What are generators?
Functions that return an iterator using yield.
62. What is yield keyword?
Used to return values one at a time.
63. What are decorators?
Functions that modify other functions.
64. What is multithreading?
Executing multiple threads simultaneously.
65. What is GIL?
Global Interpreter Lock allows only one thread execution at a time in CPython.
Libraries & Tools
66. What is Matplotlib?
A library for data visualization.
67. What is Scikit-learn?
A machine learning library.
68. What is Django?
A high-level web framework.
69. What is Flask?
A lightweight web framework.
70. What is pip?
Package installer for Python.
Practical & Project Viva
71. How to improve Python code performance?
-
Use efficient algorithms
-
Use built-in functions
-
Avoid unnecessary loops
72. What is virtual environment used for?
To manage project dependencies separately.
73. What is version control?
Tracking changes using tools like Git.
74. Difference between Python 2 and Python 3?
Python 3 supports Unicode by default and better syntax.
75. What is API?
Application Programming Interface allows communication between software.
No comments:
Post a Comment