Basic Python Interview Questions with Answers (1-10)
1. What is Python?
Python is a high-level, interpreted programming language. It's known for its simplicity, readability,
and versatility. Python is used for web development, automation, data analysis, machine learning,
and more.
2. What are Python's key features?
- Easy to read and write
- Interpreted language
- Dynamically typed
- Extensive libraries (like Pandas, NumPy, etc.)
- Supports OOP and functional programming
3. What is a variable in Python?
A variable is a container to store data. In Python, you don't need to declare a data type. Example:
x = 10
4. What are data types in Python?
Common data types are:
- int (integer)
- float (decimal)
- str (string)
- bool (True/False)
- list, tuple, dict, set
5. What is a list in Python?
A list is an ordered, changeable collection. It can hold mixed data types.
Example:
my_list = [1, 'apple', 3.5]
6. What is the difference between a list and a tuple?
- List: mutable (can change), written with []
- Tuple: immutable (cannot change), written with ()
7. What is a dictionary in Python?
A dictionary stores key-value pairs. It's unordered and mutable.
Example:
my_dict = {'name': 'Manoj', 'age': 22}
8. What is a function in Python?
A function is a reusable block of code that performs a specific task.
Example:
def greet():
print('Hello')
9. What is the difference between '==' and 'is'?
'==' compares values. 'is' compares identities (memory locations).
Example:
'a' == 'a' is True, but a is b may be False unless a and b refer to the same object.
10. What are loops in Python?
Loops repeat a block of code.
- for loop: iterate over a sequence
- while loop: run while a condition is True