Complete Python Interview Questions
Complete Python Interview Questions
Q: What is Python?
A: Python is a high-level, interpreted programming language known for its simplicity and readability.
It supports multiple paradigms like object-oriented, procedural, and functional programming. Python
Syntax:
list1 = [1, 2, 3]
tuple1 = (1, 2, 3)
Example:
A: Indentation defines blocks of code. Python uses indentation instead of braces. Incorrect
Example:
name = 'Alice'
print(type(name))
- if
- elif
- else
Example:
if x > 0:
print('Positive')
Example:
print(fruit)
Example:
print(args)
print(kwargs)
Example:
square = lambda x: x * x
print(square(4)) # 16
Example:
A: - == compares values
x = [1,2]
y = [1,2]
x == y # True
x is y # False
try:
risky()
Python Interview and Practice Questions
except Exception as e:
print(e)
A: A module is a .py file containing Python definitions. Use import module_name to use it.
Example:
def gen():
yield 1
yield 2
Example:
with open('file.txt') as f:
data = f.read()
Q: What is a decorator?
Example:
@decorator
def func():
pass
Example:
print(f.read())