
Python Data Structures
Lists, dictionaries, sets, tuples, list comprehensions, generators, itertools
1What is the fundamental difference between a list and a tuple in Python?
What is the fundamental difference between a list and a tuple in Python?
Answer
Lists are mutable (can be modified after creation) while tuples are immutable (cannot be modified). This immutability makes tuples hashable and usable as dictionary keys, unlike lists. Tuples are also slightly more performant in terms of memory usage and access speed.
2Which method should be used to add an element at the end of a Python list?
Which method should be used to add an element at the end of a Python list?
Answer
The append() method adds a single element at the end of a list. It modifies the list in place and returns None. To add multiple elements, use extend() or the += operator. The insert() method allows adding at a specific position.
3How to create an empty dictionary in Python?
How to create an empty dictionary in Python?
Answer
An empty dictionary can be created with {} or dict(). The {} syntax is more concise and slightly faster. The {} notation creates an empty dictionary, while set() creates an empty set. For an empty set, you must use set() because {} is reserved for dictionaries.
What is the result of the expression [x**2 for x in range(5)]?
What characteristic distinguishes a set from other Python collections?
+17 interview questions
Other Data Science & ML interview topics
Python Basics
Python Object-Oriented Programming
Git Fundamentals
SQL Basics
NumPy Fundamentals
Pandas Basics
Jupyter & Google Colab
SQL Joins & Advanced Queries
Advanced Pandas
Visualization with Matplotlib & Seaborn
Interactive Visualizations with Plotly
Descriptive Statistics
Inferential Statistics
Web Scraping
BigQuery & Cloud Data
Feature Engineering
Supervised ML: Regression
Supervised ML: Classification
Decision Trees & Ensembles
Unsupervised ML
ML Pipelines & Validation
Time Series & Forecasting
Deep Learning Fundamentals
TensorFlow & Keras
CNN & Image Classification
RNN & Sequences
Transformers & Attention
NLP & Hugging Face
GenAI & LangChain
MLOps & Deployment
Master Data Science & ML for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free