Python Interview 40 Basic 40 Intermediate
Python Interview 40 Basic 40 Intermediate
Q: What is Python?
A: Python is a high-level, interpreted programming language known for its simplicity and readability.
is widely used in web development, data analysis, artificial intelligence, and more.
A: Variables in Python are containers for storing data values. You don't need to declare their type
x=5
name = 'Alice'
A: Use the hash symbol (#) for single-line comments. For multi-line comments, use triple quotes:
'''
This is a
multi-line comment
'''
A: Lists are mutable and defined using square brackets []. Tuples are immutable and use
list1 = [1, 2, 3]
tuple1 = (1, 2, 3)
- int
- float
- str
- list
- tuple
- dict
- set
- bool
x = 10
A: Indentation refers to spaces or tabs used to define blocks of code. It is mandatory in Python.
x = 5 # assigns 5 to x
- int('5') => 5
A: A function is a block of reusable code defined using the def keyword. Example:
def greet(name):
A: *args allows a function to accept any number of positional arguments. **kwargs allows any
Example:
pass
square = lambda x: x * x
print(square(5)) # 25
A: A file containing Python definitions and code. Use `import module_name` to include it.
x = [1]
y = [1]
x == y # True
x is y # False
try:
risky_code()
except Exception as e:
print(e)
with open('file.txt') as f:
data = f.read()
A: Generators yield items one at a time using `yield`. They are memory-efficient for large datasets.
Example:
def gen():
yield 1
Python Interview and Practice Questions
yield 2