What distinguishes an expression from a statement?
Expressions produce values, while statements perform actions such as assignment, importing, defining functions, or controlling execution.
Study 1 Python Syntax and Program Structure with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What distinguishes an expression from a statement?
Expressions produce values, while statements perform actions such as assignment, importing, defining functions, or controlling execution.
What is a common order for a Python source file?
A module docstring may come first, followed by imports, constants and configuration, function and class definitions, and program-starting code.
Why use if __name__ == "__main__":?
When a file runs directly, __name__ equals "__main__"; when imported, it does not, so the guarded main() call runs only for direct execution.
How can one Python statement span multiple lines?
A statement may continue across physical lines inside parentheses, brackets, or braces. This is usually clearer and safer than using a backslash.
How do comments differ from docstrings?
A comment starts with # outside a string and is ignored during parsing. A first string literal in a module, function, or class is a docstring.
How does Python delimit code blocks?
Indentation defines Python code blocks. A compound-statement header ends with a colon, and its controlled suite is indented beneath it; four spaces per level is conventional.
What naming rules distinguish count from Count?
Python is case-sensitive, so count and Count are different names. Names may contain letters, digits, and underscores but cannot begin with a digit.
What does Python assignment bind?
Assignment binds a name to an object; it does not necessarily copy the object. Multiple assignment can bind several names or swap references.
What is a literal in Python?
A literal is source-code notation for a value, such as 42, "hello", True, None, [1, 2, 3], or {"language": "Python"}.
How do / and // differ?
The operator // performs floor division: 7 // 2 evaluates to 3. The operator / performs true division, so 7 / 2 evaluates to 3.5.
What is short-circuit evaluation?
and and or use short-circuit evaluation, stopping when the result is determined. They return one of their operands, not necessarily True or False.
What do print()'s sep and end control?
print() writes objects as text. Its sep argument separates multiple objects, while end replaces the default trailing newline.