Start by defining each key clearly, then contrast their purposes and constraints. Use a concrete example to illustrate how they work together in a relational schema. Emphasize the implications for data integrity and performance.
Pro tip: Mention that while primary keys enforce entity integrity, foreign keys enforce referential integrity, and both are crucial for maintaining consistent relationships in a database. Also, note that foreign keys can reference a primary key in another table, creating a parent-child relationship.
Explain that a primary key uniquely identifies each record in a table and cannot be null or duplicated.
Explain that a foreign key is a field (or collection of fields) in one table that refers to the primary key in another table, establishing a link between them.
Contrast the constraints: primary key enforces uniqueness and non-nullness; foreign key enforces referential integrity, ensuring values match an existing primary key or are null.
Provide a simple example, such as a Customers table with CustomerID as primary key and an Orders table with CustomerID as foreign key.
Mention how these constraints affect data integrity, indexing, and performance, and how they are used in database design.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
They gave a small schema and asked for a few queries.
Start by clarifying the schema and the specific questions you need to answer with the queries. Then, write each query step by step, explaining your choice of SELECT, JOIN, and GROUP BY clauses, and validate with sample data or edge cases.
Pro tip: Always consider NULLs and duplicate rows when using JOINs and GROUP BY; explicitly handle them to show you understand data integrity. Also, mention indexes on join columns to demonstrate performance awareness.
Ask questions to understand the tables, columns, relationships, and what the queries need to return. Confirm any assumptions about data types and constraints.
Identify the columns needed and write a simple SELECT statement, using aliases and filtering with WHERE if necessary. Explain why you chose those columns.
Determine which tables to join and the join conditions. Choose INNER, LEFT, or other join types based on whether you need to include unmatched rows, and explain your choice.
Group rows by the appropriate columns and use aggregate functions like COUNT, SUM, AVG. Ensure all non-aggregated columns are in the GROUP BY clause.
Check for correctness with sample data, consider NULL handling, and mention potential indexes or query optimizations. Discuss how you would test the queries.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Start by defining mutability in Python—objects whose state can be changed after creation—and contrast it with immutability. Then explain how lists are mutable and tuples are immutable, highlighting practical implications like performance, safety, and use cases. Finally, connect this to broader software engineering trade-offs, such as when to choose one over the other.
Pro tip: Mention that immutability makes tuples hashable and thus usable as dictionary keys or set elements, while lists are not—this shows you understand real-world consequences beyond textbook definitions.
Clearly state that mutable objects can be modified after creation (e.g., lists, dicts, sets), while immutable objects cannot (e.g., tuples, strings, numbers).
Describe that lists support in-place modification (append, remove, item assignment), whereas tuples do not; any 'modification' creates a new object.
Cover performance (tuples are faster and use less memory), safety (immutability prevents accidental changes), and hashability (tuples can be dict keys, lists cannot).
Explain when to use each: lists for homogeneous sequences that change, tuples for heterogeneous fixed data or as records; mention that immutability aids in concurrent programming and caching.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Start by defining the LEGB rule (Local, Enclosing, Global, Built-in) as the core of Python's scoping. Then explain how variable references are resolved at runtime, using examples to illustrate each scope level and the role of the global and nonlocal keywords. Finally, discuss common pitfalls like the UnboundLocalError and how to avoid them.
Pro tip: Mention that Python's scoping is determined at compile time, not runtime, which explains why assigning to a variable anywhere in a function makes it local throughout that function. This shows deep understanding and can preempt follow-up questions.
Explain that Python resolves variable names using the LEGB rule: Local, Enclosing, Global, Built-in. This is the foundation for understanding scoping.
Briefly describe each scope: local (inside current function), enclosing (in outer functions), global (module level), and built-in (predefined names). Give a simple example for each.
Clarify that reading a variable searches through LEGB, but assigning to a variable makes it local to the current scope unless declared global or nonlocal. Mention the UnboundLocalError.
Show how global allows modification of a global variable from within a function, and nonlocal allows modification of a variable in an enclosing (but not global) scope.
Mention pitfalls like accidental shadowing, using global variables unnecessarily, and the importance of clear scoping for maintainability. Suggest avoiding global where possible.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
For each snippet, mentally simulate the code line by line, paying attention to Python-specific behaviors like mutability, scoping, and evaluation order. Then state the output clearly and briefly explain the underlying rule to show understanding.
Pro tip: When uncertain, don't guess—walk through the code step by step out loud, and if you're still unsure, say what you'd test or look up. Interviewers value a methodical approach over a lucky guess.
Quickly read the snippet and restate what it does in plain English to ensure you understand the goal.
Simulate the code line by line, tracking variable values and object states, especially for loops and function calls.
Check for common Python gotchas: mutable default arguments, late binding closures, integer caching, string interning, and operator precedence.
Give the exact output, then explain the key rule or behavior that produces it, referencing Python's semantics.
If time permits, mention how you could verify (e.g., using id(), dis, or a quick mental test) or note edge cases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.