Python interview Question & Answer
1. What is Python?
Python is a high-level, interpreted, object-oriented programming language known for its simplicity and readability.
2. What are the advantages of Python?
- Easy syntax
- Platform independent
- Dynamically typed
- Large standard library
- Supports multiple programming paradigms
3. Is Python case-sensitive?
Yes, Python is case-sensitive.
4. What is PEP 8?
PEP 8 is the official Python coding style guideline.
5. What are keywords in Python?
Reserved words that have predefined meanings (e.g., if, else, for, while).
6. What are built-in data types in Python?
int, float, str, list, tuple, set, dict, bool
7. Difference between list and tuple?
|
List |
Tuple |
|
Mutable |
Immutable |
|
Slower |
Faster |
|
Uses [] |
Uses () |
8. What is a dictionary?
A collection of key-value pairs.
{"name": "Amit", "age": 22}
9. What is conditional statement?
Used to execute code based on conditions (if, elif, else).
10. What loops are available in Python?
- for loop
- while loop
11. What is break and continue?
- break exits the loop
- continue skips the current iteration
12. What is a function?
A reusable block of code.
13. What is return keyword?
Used to send value back from a function.
14. What is lambda function?
An anonymous single-line function.
lambda x: x * 2
15. What is OOP?
Programming based on objects and classes.
16. What are OOP concepts?
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
17. What is constructor?
A special method (__init__) used to initialize objects.
18. What is exception?
An error that occurs during program execution.
19. How do you handle exceptions?
try:
x = 10 / 0
except ZeroDivisionError:
print("Error")
20. What is generator?
A function that uses yield to return values one at a time.
21. What is decorator?
A function that modifies another function.
22. What is GIL?
Global Interpreter Lock ensures only one thread runs Python bytecode at a time.
23. What is multithreading?
Executing multiple threads concurrently.
24. How do you open a file?
open("data.txt", "r")
25. Difference between read() and readline()?
- read() reads entire file
- readline() reads one line
26. Difference between is and ==?
- is → memory comparison
- == → value comparison
27. What is pip?
Python package manager.
28. What is virtual environment?
Isolated Python environment for projects.
29. What is garbage collection?
Automatic memory management in Python.
Web Development, Data Science, AI, Automation, DevOps
Categories: python programming