Python Viva Questions with Answers (50)
1. What is Python?
Python is a high-level, interpreted, and general-purpose programming language.
2. Who developed Python?
Python was developed by Guido van Rossum.
3. Is Python case-sensitive?
Yes, Python is case-sensitive.
4. What type of language is Python?
Python is an interpreted and object-oriented language.
5. What is an interpreter?
An interpreter executes code line by line.
6. What is PEP 8?
PEP 8 is the official style guide for Python code.
7. What is a variable?
A variable is used to store data values.
8. How do you comment in Python?
Using # symbol.
9. What are Python keywords?
Reserved words with predefined meaning (e.g., if, else, while).
10. What is a data type?
It defines the type of data a variable holds.
11. Name basic data types in Python.
int, float, string, boolean.
12. What is a list?
A list is a mutable, ordered collection of items.
13. What is a tuple?
A tuple is an immutable, ordered collection of items.
14. Difference between list and tuple?
List is mutable, tuple is immutable.
15. What is a dictionary?
A collection of key-value pairs.
16. What is a set?
An unordered collection of unique elements.
17. What is indentation in Python?
Whitespace used to define code blocks.
18. What happens if indentation is wrong?
It raises an IndentationError.
19. What is a function?
A block of reusable code.
20. How to define a function?
Using the def keyword.
21. What is return statement?
It sends a value back from a function.
22. What is recursion?
A function calling itself.
23. What is a loop?
Used to repeat a block of code.
24. Types of loops in Python?
for loop and while loop.
25. What is break statement?
It stops the loop execution.
26. What is continue statement?
It skips the current iteration.
27. What is pass statement?
A null statement that does nothing.
28. What is input() function?
Used to take user input.
29. What is type() function?
Returns the data type of a variable.
30. What is len() function?
Returns the length of an object.
31. What is slicing?
Extracting a part of a sequence.
32. What is a string?
A sequence of characters.
33. Are strings mutable?
No, strings are immutable.
34. What is file handling?
Reading and writing data to files.
35. File modes in Python?
r, w, a, x.
36. What is exception?
An error that occurs during execution.
37. What is try-except block?
Used to handle exceptions.
38. What is finally block?
Always executes, whether error occurs or not.
39. What is import statement?
Used to include modules.
40. What is a module?
A file containing Python code.
41. What is a package?
A collection of modules.
42. What is lambda function?
A small anonymous function.
43. What is OOP?
Object-Oriented Programming.
44. Main OOP concepts?
Class, Object, Inheritance, Polymorphism, Encapsulation.
45. What is a class?
A blueprint for creating objects.
46. What is an object?
An instance of a class.
47. What is inheritance?
One class acquiring properties of another.
48. What is polymorphism?
Same function name, different behavior.
49. What is encapsulation?
Binding data and methods together.
50. Why Python is popular?
Simple syntax, large libraries, and wide applications.