Python Interview Questions
Python Interview Questions
- Interpreted language
- Dynamically typed
- High-level language
- Extensive libraries
- Text: str
- Mapping: dict
- Boolean: bool
- NoneType: None
Example:
print(args)
Python Interview Questions and Answers
print(kwargs)
Example:
def decorator(func):
def wrapper():
print('Before')
func()
print('After')
return wrapper
@decorator
def greet():
print('Hello')
Example:
Example:
a = [1]; b = a; c = [1]
print(a == c) # True
print(a is c) # False
Example:
def gen():
yield 1
yield 2
Example:
import copy
copy.deepcopy(obj)
Example:
add = lambda x, y: x + y
GIL ensures only one thread executes Python bytecode at a time. It affects multi-threading.
Example:
@staticmethod
@classmethod
- ZeroDivisionError
- TypeError
- ValueError
- IndexError
- KeyError
Example:
try:
1/0
except ZeroDivisionError:
print('Error')