What is the difference between a list and a tuple in Python?
Lists are mutable (can be changed after creation) and defined with square brackets []. Tuples are immutable (cannot be changed) and defined with parentheses (). Tuples are generally faster and use less memory. Use tuples for fixed data like coordinates or function return values, and lists for collections that need modification.
What is the difference between *args and **kwargs?
*args allows a function to accept any number of positional arguments as a tuple. **kwargs allows any number of keyword arguments as a dictionary. In AI tooling, **kwargs is extensively used for passing model parameters: model.fit(**training_config). Both are essential for writing flexible wrapper functions around LLM APIs and model training loops.
Explain list comprehensions vs generator expressions for processing datasets.
List comprehensions create the entire list in memory: [embed(text) for text in docs]. Generator expressions are lazy and process one at a time: (embed(text) for text in docs). For large AI datasets (e.g., processing 100k documents for embedding), always use generator expressions or batch processing to avoid OOM errors. Generators are also ideal for streaming predictions from a model.
Know your weak spots before the interview
10-question AI readiness assessment → personalized study plan.
Take Free Assessment →Unlock 3,000+ Interview Questions
Get full access to all interview questions with detailed answers, explanations, and real company context
Enroll Python Pack →