31. What are the differences between Python 2 and Python 3?
Python 3 introduced many improvements: print is a function (print()), better Unicode support, integer division changes, and removed deprecated features. Python 2 is now end-of-life.32. How do you use regular expressions in Python?
With the
re module, e.g., re.search(), re.findall(). They help match, search, or replace patterns in strings.33. What is the purpose of the
with statement? Manages resources like file opening/closing automatically ensuring cleanup, e.g.,
34. Explain how to use virtual environments.
Isolate project dependencies using
venv or virtualenv to avoid conflicts between package versions across projects.35. How do you connect Python with SQL databases?
Using libraries like
sqlite3, SQLAlchemy, or pymysql to execute SQL queries and fetch results into Python.36. What is the role of the
__init__.py file? Marks a directory as a Python package and can initialize package-level code.
37. How do you handle JSON data in Python?
Use
json module: json.load() to parse JSON files and json.dumps() to serialize Python objects to JSON.38. What are generator functions and why use them?
Functions that yield values one at a time using
yield, saving memory by lazy evaluation, ideal for large datasets.39. How do you perform feature engineering with Python?
Create or transform variables using Pandas (e.g., creating dummy variables, extracting date parts), normalization, or combining features.
40. What is the purpose of the Pandas
.pivot_table() method? Creates spreadsheet-style pivot tables for summarizing data, allowing aggregation by multiple indices.
No comments:
Post a Comment