Python Interview Questions – Basics
1. What is Python?
Python is a high-level, interpreted programming language known for readability.
2. What are Python's key features?
- Easy syntax
- Interpreted
- Object-oriented
- Large libraries
3. What is PEP 8?
PEP 8 is the style guide for writing Python code.
4. Difference between list and tuple?
Lists are mutable, tuples are immutable.
Data Types and Functions
1. What are Python data types?
int, float, str, list, tuple, set, dict
2. What is a function?
A reusable block of code.
3. What are *args and **kwargs?
*args allows variable positional arguments.
**kwargs allows variable keyword arguments.
4. What is lambda?
Anonymous function defined using lambda keyword.
Object-Oriented Programming
1. What is OOP?
Programming based on objects and classes.
2. What is inheritance?
A class derives properties from another class.
3. What is polymorphism?
Same function behaves differently.
4. What is encapsulation?
Binding data and methods together.
Advanced Python Topics
1. What is a decorator?
A function that modifies another function.
2. What is generator?
Function that yields values one at a time.
3. What is GIL?
Global Interpreter Lock that allows only one thread execution at a time.
4. What is virtual environment?
Isolated environment for Python projects.
Coding and Practical Questions
1. Reverse a string:
s = 'hello'
print(s[::-1])
2. Check palindrome:
s = 'madam'
print(s == s[::-1])
3. Find largest number in list:
lst = [1,2,3]
print(max(lst))
4. Count frequency of elements:
from collections import Counter
print(Counter(lst))