Python Programming Interview Questions and Answers (BSc Computer Science)
1. What is Python?
Python is a high-level, interpreted, and general-purpose programming language. It is known for its simple
syntax, readability, and wide range of libraries.
2. What are Python's key features?
- Easy to learn and read
- Interpreted and dynamically typed
- Supports multiple programming paradigms
- Extensive standard libraries
- Platform-independent
3. What are Python data types?
- Numeric: int, float, complex
- Sequence: list, tuple, range
- Text: str
- Set: set, frozenset
- Mapping: dict
- Boolean: bool
- None: NoneType
4. What is the difference between a list and a tuple?
List:
- Mutable
- Defined with []
- Slower
Python Programming Interview Questions and Answers (BSc Computer Science)
Tuple:
- Immutable
- Defined with ()
- Faster
5. What is a function in Python?
A function is a block of reusable code defined using 'def'.
Example:
def greet(name):
return f"Hello, {name}"
6. What is the difference between 'is' and '==' in Python?
- '==' checks value equality
- 'is' checks identity (memory location)
7. What are Python's control statements?
- Conditional: if, elif, else
- Loops: for, while
- Loop control: break, continue, pass
8. How does exception handling work in Python?
Handled using try, except, else, and finally.
Python Programming Interview Questions and Answers (BSc Computer Science)
Example:
try:
x=1/0
except ZeroDivisionError:
print("Cannot divide by zero")
9. What is a dictionary in Python?
A dictionary is a collection of key-value pairs.
Example:
student = {"name": "Alice", "age": 20}
10. What is a lambda function?
A lambda function is an anonymous function defined using 'lambda'.
Example:
square = lambda x: x * x