What distinguishes a Python statement from an expression?
A statement is an instruction that performs an action; an expression combines values, names, operators, or calls to produce a value.
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 a Python statement from an expression?
A statement is an instruction that performs an action; an expression combines values, names, operators, or calls to produce a value.
How does Python define statement blocks?
Python uses indentation to group statements into blocks. A colon introduces the block after compound statements such as `if`, `for`, `while`, and `def`.
What does `pass` do in an empty Python block?
Use `pass` when a syntactically required block has no action yet; an indented block cannot be empty.
How does Python recognize a comment?
A comment begins with `#` and continues to the end of the physical line. Python ignores it when interpreting the program.
What two rules govern Python names?
Python is case-sensitive, so `total`, `Total`, and `TOTAL` are different names. A name cannot begin with a digit.
What is a Python literal?
A literal is notation that directly represents a value, such as `42`, `19.95`, `
How do `=` and `==` differ in Python?
Assignment evaluates the right-hand side and binds its result to the name on the left. It uses `=`, whereas value comparison uses `==`.
How do `/` and `//` differ?
Python’s `/` operator performs regular division and produces a floating-point result; `//` performs floor division and discards the fractional part toward negative infinity.
What do Python’s `and`, `or`, and `not` operators do?
`and` is true only when both operands are true; `or` is true when at least one operand is true; `not` reverses a Boolean result.
Which operators test membership?
Use `in` and `not in` to test membership in a collection, such as whether an item occurs in a list.
When should Python use `is` instead of `==`?
`is` and `is not` test object identity. They are commonly used with `None`; use `==` for ordinary value comparison.
How can parentheses change operator evaluation order?
Parentheses override normal precedence. Without them, multiplication and division are evaluated before addition and subtraction, so `2 + 3 * 4` produces `14`.