Core Syntax Flashcards
7 cards from real Python practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Core Syntax flashcards as text
What happens when you use `*args` in a function definition?
Answer: It collects extra positional arguments into a tuple
`*args` collects all extra positional arguments passed to the function into a tuple.
What is the output of `print('ab' * 3)`?
Answer: 'ababab'
Multiplying a string by an integer repeats it that many times, so `'ab' * 3` produces `'ababab'`.
Which statement about Python indentation is correct?
Answer: Indentation defines code blocks and is syntactically required
Python uses indentation to delimit code blocks; incorrect or inconsistent indentation causes an `IndentationError`.
What does the `\t` escape sequence represent in a Python string?
Answer: A tab character
`\t` is the escape sequence for a horizontal tab character in Python strings.
Which of the following will raise a `TypeError` in Python?
Answer: '3' + 3
You cannot concatenate a string and an integer directly; `'3' + 3` raises a `TypeError` because the operands are of incompatible types.
What is the purpose of the `__name__ == '__main__'` guard in a Python script?
Answer: It runs code only when the script is executed directly, not imported
When a module is imported, `__name__` is set to the module name; when run directly, it is `'__main__'`, so this guard prevents code from running on import.
What is the result of `sorted([3, 1, 2], reverse=True)`?
Answer: [3, 2, 1]
`sorted()` returns a new sorted list; with `reverse=True` it sorts in descending order, yielding `[3, 2, 1]`.