Python Interview Questions
Python Interview Questions
Python ................................................................................................................................... 2
1. popular applications of Python in the world of technology ................................................ 2
2. benefits of using Python language ................................................................................... 2
3. Is Python a compiled language or an interpreted language? .............................................. 3
5. What is the difference between a Mutable datatype and an Immutable data type? ............ 3
6. How are arguments passed by value or by reference in Python? ....................................... 3
7. What is the difference between a Set and Dictionary? ...................................................... 4
8. What is List Comprehension? Give an Example. ............................................................... 4
9. What is a lambda function? ............................................................................................. 4
10. What is a pass in Python? .............................................................................................. 4
12. How is Exceptional handling done in Python? ................................................................. 4
14. Difference between for loop and while loop in Python..................................................... 5
15. Can we Pass a function as an argument in Python? ........................................................ 5
16. What are *args and *kwargs?......................................................................................... 6
18. What is Scope in Python? .............................................................................................. 6
20. What is a dynamically typed language? .......................................................................... 7
21. What is a break, continue, and pass in Python? .............................................................. 7
22. What are Built-in data types in Python? .......................................................................... 7
24. What is the difference between xrange and range functions? .......................................... 8
25. What is Dictionary Comprehension? Give an Example .................................................... 8
26. Is Tuple Comprehension? If yes, how, and if not why? .................................................... 9
27. Differentiate between List and Tuple? ............................................................................ 9
28. What is the difference between a shallow copy and a deep copy? ................................. 10
29. Which sorting technique is used by sort() and sorted() functions of python? .................. 10
30. What are Decorators? ................................................................................................. 10
31. How do you debug a Python program? ......................................................................... 10
32. What are Iterators in Python? ...................................................................................... 11
34. Does Python supports multiple Inheritance? ................................................................ 11
35. What is Polymorphism in Python? ................................................................................ 11
36. Define encapsulation in Python? ................................................................................. 12
37. How do you do data abstraction in Python?.................................................................. 12
38. How is memory management done in Python? ............................................................. 12
40. What is slicing in Python? ............................................................................................ 12
41. What is a namespace in Python? ................................................................................. 13
42. What is PIP?................................................................................................................ 13
44. What are Pickling and Unpickling? ............................................................................... 13
45. What is monkey patching in Python? ............................................................................ 13
46. What is __init__() in Python? ........................................................................................ 14
47. Write a code to display the current time? ..................................................................... 14
48. What are Access Specifiers in Python? ........................................................................ 14
49. What are unit tests in Python? ..................................................................................... 14
53. What is Python Switch Statement ................................................................................ 15
54. What is Walrus Operator? ........................................................................................... 15
Python
1. popular applications of Python in the world of
technology
Python is a widely-used general-purpose, high-level programming
language. It was created by Guido van Rossum in 1991 and further
developed by the Python Software Foundation. It was designed with an
emphasis on code readability, and its syntax allows programmers to
express their concepts in fewer lines of code.
It is used for:
• System Scripting
• Web Development
• Game Development
• Software Development
• Complex Mathematics
def greet():
return "Hello, "
def name():
return "John"
import m
def monkey_function(self):
print "monkey_function()"
m.GeeksClass.function = monkey_function
obj = m.GeeksClass()
obj.function()
46. What is __init__() in Python?
Equivalent to constructors in OOP terminology, __init__ is a reserved
method in Python classes. The __init__ method is called automatically
whenever a new object is initiated. This method allocates memory to the
new object as soon as it is created. This method can also be used to
initialize variables.
currenttime= time.localtime(time.time())
print (“Current time is”, currenttime)