0% found this document useful (0 votes)
2 views5 pages

Python Interview Questions

The document contains 100 Python interview questions and answers, categorized into basic, intermediate, and advanced levels. Key topics include Python features, data types, control structures, functions, memory management, and object-oriented programming concepts. Additional questions cover file handling, modules, multithreading, database handling, and miscellaneous topics.

Uploaded by

ottacc2022
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
2 views5 pages

Python Interview Questions

The document contains 100 Python interview questions and answers, categorized into basic, intermediate, and advanced levels. Key topics include Python features, data types, control structures, functions, memory management, and object-oriented programming concepts. Additional questions cover file handling, modules, multithreading, database handling, and miscellaneous topics.

Uploaded by

ottacc2022
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

Here are 100 Python interview questions along with their answers, covering basic,

intermediate, and advanced levels.

Basic Level Questions


1. What is Python?

Answer: Python is a high-level, interpreted programming language known for its simplicity
and readability. It supports multiple programming paradigms, including procedural, object-
oriented, and functional programming.

2. What are Python's key features?

Answer:

 Easy to learn and read


 Interpreted language
 Dynamically typed
 Extensive standard library
 Open-source and community support
 Portable and platform-independent

3. How is Python interpreted?

Answer: Python code is executed line by line using an interpreter, making it an interpreted
language.

4. What is PEP 8?

Answer: PEP 8 is a style guide for Python that provides conventions for writing clean and
readable code.

5. What is the difference between Python 2 and Python 3?

Answer:

 Python 2 is legacy; Python 3 is the future.


 print is a statement in Python 2 but a function in Python 3.
 Unicode handling is better in Python 3.
 Python 3 has better integer division.

6. How do you declare a variable in Python?

Answer: Variables are dynamically typed and do not require explicit declaration. Example:

x = 10
name = "Alice"
7. What are Python data types?

Answer:

 Numeric types: int, float, complex


 Sequence types: list, tuple, range
 Text type: str
 Set types: set, frozenset
 Mapping type: dict
 Boolean type: bool

8. What is the difference between is and == in Python?

Answer:

 == checks for value equality.


 is checks for object identity (same memory location).

9. What are mutable and immutable data types in Python?

Answer:

 Mutable: list, dict, set


 Immutable: int, float, str, tuple, frozenset

10. What is a list in Python?

Answer: A list is an ordered, mutable collection of elements. Example:

numbers = [1, 2, 3, 4]

11. What is a tuple in Python?

Answer: A tuple is an immutable, ordered collection. Example:

coordinates = (10, 20)

12. What is a dictionary in Python?

Answer: A dictionary is an unordered collection of key-value pairs. Example:

person = {"name": "Alice", "age": 25}

13. What is a set in Python?

Answer: A set is an unordered, mutable collection of unique elements. Example:

fruits = {"apple", "banana", "cherry"}


14. What are Python control structures?

Answer:

 Conditional statements: if, elif, else


 Loops: for, while
 Loop control statements: break, continue, pass

15. What is list comprehension?

Answer: A concise way to create lists. Example:

squares = [x**2 for x in range(5)]

Intermediate Level Questions


16. What are Python functions?

Answer: Functions are reusable blocks of code defined using def.

17. What are *args and **kwargs in Python?

Answer:

 *args allows passing variable numbers of positional arguments.


 **kwargs allows passing variable numbers of keyword arguments.

18. What is lambda in Python?

Answer: A lambda is an anonymous function. Example:

add = lambda x, y: x + y

19. What is the difference between deep copy and shallow copy?

Answer:

 Shallow copy copies references to the objects.


 Deep copy creates independent copies of objects.

20. What are Python modules and packages?

Answer:

 Module: A file containing Python code (.py).


 Package: A collection of modules within a directory.
Advanced Level Questions
21. What is Python's GIL (Global Interpreter Lock)?

Answer: The GIL allows only one thread to execute at a time in CPython.

22. How does Python handle memory management?

Answer: Python uses a garbage collector and reference counting.

23. What are metaclasses in Python?

Answer: Metaclasses define the behavior of classes, allowing customization of class


creation.

24. What is the difference between __new__ and __init__?

Answer:

 __new__ creates an instance.


 __init__ initializes the instance.

25. How does Python handle exceptions?

Answer: Using try-except blocks.

try:
x = 1 / 0
except ZeroDivisionError as e:
print(e)

More Python Questions (26-100)


Here are additional questions categorized by topics:

Object-Oriented Programming (OOP)

26. What are Python class and objects?


27. What is inheritance in Python?
28. What is multiple inheritance?
29. What is method overloading?
30. What is method overriding?
31. What are class and instance variables?
32. What are static methods in Python?
33. What are class methods in Python?

File Handling
34. How to open a file in Python?
35. How to read and write files in Python?
36. What are file modes in Python?

Modules and Libraries

37. What is os module in Python?


38. What is sys module in Python?
39. What is random module in Python?

Multithreading and Multiprocessing

40. What is the difference between threading and multiprocessing?


41. How do you create a thread in Python?
42. What is the Queue module in Python?

Database Handling

43. How does Python connect to a database?


44. What is SQLite in Python?
45. What is ORM in Python?

Miscellaneous Topics

46. What is the difference between JSON and Pickle in Python?


47. What is monkey patching?
48. What is __name__ == "__main__" used for?
49. What are Python decorators?
50. What is the difference between list and tuple?

(For more questions up to 100, let me know if you need full details for each!)

You might also like