Python Programming and Data Science Questions
Setting up Environment & Basic Python Commands (Questions 1-4)
1. What are the key differences between Python 2 and Python 3, and what steps
would you take to set up a Python 3 development environment on Windows,
macOS, and Linux?
2. Explain the Python interactive shell (REPL) and demonstrate how to use basic
Python commands like print(), input(), type(), and help() with practical examples.
3. What is the Python PATH environment variable, and how do you configure it? Also,
explain the difference between running Python scripts using python [Link] vs
python3 [Link].
4. Describe the purpose and usage of virtual environments in Python. How do you
create, activate, and deactivate a virtual environment using venv or virtualenv?
Creating Python Scripts, Modules, Packages & Libraries (Questions 5-8)
5. What is the difference between a Python script, module, and package? Create a
simple example showing how to import and use functions from a custom module.
6. Explain the __init__.py file's role in Python packages and demonstrate how to
create a package structure with multiple modules and subpackages.
7. What are Python libraries and how do they differ from modules and packages?
Explain the process of installing external libraries using pip and managing
dependencies with [Link].
8. Describe the concept of namespaces in Python and explain how the import
statement works. What's the difference between import module, from module
import function, and import module as alias?
Conditions, Loops, Lists & Dictionaries (Questions 9-14)
9. Write a Python program that demonstrates all types of conditional statements (if,
elif, else) and logical operators (and, or, not). Include nested conditions and explain
short-circuit evaluation.
10. Compare and contrast for loops and while loops in Python. Provide examples using
range(), enumerate(), and zip() functions, and explain when to use break, continue,
and else with loops.
11. Explain list comprehensions in Python and provide examples that demonstrate
filtering, mapping, and nested comprehensions. How do they compare to
traditional loops in terms of performance and readability?
12. What are the key differences between lists, tuples, and sets in Python?
Demonstrate common operations like slicing, indexing, adding, removing elements,
and membership testing.
13. Create a comprehensive example showcasing dictionary operations including
creation, accessing values, adding/removing items, dictionary comprehensions,
and methods like keys(), values(), items().
14. Write a program that combines lists and dictionaries to solve a real-world problem,
such as managing student records with grades and calculating statistics.
User Defined Functions & Classes (Questions 15-19)
15. **Explain function definition syntax in Python, including parameters, default
arguments, keyword arguments, and variable-length arguments (*args, kwargs).
Provide examples of each.
16. What is the difference between local and global scope in Python? Demonstrate the
use of global and nonlocal keywords, and explain the LEGB (Local, Enclosing,
Global, Built-in) rule.
17. Define object-oriented programming concepts (encapsulation, inheritance,
polymorphism) and create a Python class hierarchy that demonstrates these
principles with methods, attributes, and constructors.
18. Explain the difference between instance variables and class variables. Demonstrate
method types: instance methods, class methods (@classmethod), and static
methods (@staticmethod).
19. What are magic methods (dunder methods) in Python? Implement a custom class
with __init__, __str__, __repr__, __len__, and __add__ methods.
Data Classes & Anaconda (Questions 20-22)
20. What are Python data classes and how do they simplify class creation? Compare
traditional classes with data classes using @dataclass decorator, including features
like default values, immutability, and automatic method generation.
21. Explain what Anaconda is and its advantages for data science and scientific
computing. How do you install packages using conda vs pip, and what is the
difference between conda environments and virtual environments?
22. Describe the Anaconda ecosystem including Jupyter Notebook, Spyder, and conda
package manager. How do you create and manage conda environments for
different projects?
NumPy & Pandas (Questions 23-26)
23. What is NumPy and why is it fundamental for scientific computing in Python?
Demonstrate array creation, indexing, slicing, and broadcasting with practical
examples. Explain the performance advantages over Python lists.
24. Explain NumPy array operations including mathematical functions, aggregation
functions, and array manipulation methods like reshape, transpose, and
concatenation. How do you handle missing values in NumPy?
25. What is Pandas and how does it extend NumPy for data analysis? Compare Series
and DataFrame objects, demonstrate data loading from CSV/Excel files, and show
basic data exploration techniques.
26. Create a comprehensive Pandas example showing data cleaning, filtering, grouping,
merging DataFrames, and handling missing data. Include operations like groupby(),
merge(), join(), and pivot_table().
Matplotlib & SciPy (Questions 27-28)
27. Demonstrate data visualization using Matplotlib by creating multiple plot types
(line plots, bar charts, histograms, scatter plots, subplots). Explain customization
options including labels, legends, colors, and styling.
28. What is SciPy and how does it complement NumPy? Provide examples of statistical
functions, optimization, integration, and scientific computing tasks using SciPy
modules.
Linear Algebra: Vectors, Matrices & Linear Equations (Questions 29-30)
29. Using NumPy, demonstrate vector operations (dot product, cross product,
magnitude, normalization) and matrix operations (multiplication, transpose,
inverse, determinant). Explain broadcasting rules for matrix-vector operations.
30. How do you solve systems of linear equations using NumPy and SciPy?
Demonstrate solving Ax = b using different methods including [Link](),
matrix inversion, and iterative methods. Include examples of overdetermined and
underdetermined systems.