What does `=` mean in Python?
Assignment evaluates the expression on the right and associates its result with the name on the left. The `=` symbol assigns a value; it does not test mathematical equality.
Study 03 — Python Programming Fundamentals with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What does `=` mean in Python?
Assignment evaluates the expression on the right and associates its result with the name on the left. The `=` symbol assigns a value; it does not test mathematical equality.
Can a Python variable change type?
A variable’s current value determines its type; the name itself is not permanently fixed to one type. For example, `item` can refer first to `10` and later to the string `"ten"`.
What is multiple assignment?
`width, height = 8, 5` assigns 8 to `width` and 5 to `height`. Multiple assignment can also exchange values, as in `left, right = right, left`.
Why convert the result of `input()`?
`input()` returns text, so numeric input must be converted before arithmetic. Use `int()` for whole numbers or `float()` for numbers that may contain a fractional part.
What does an f-string do?
An f-string inserts expressions inside braces, such as `f"{name} worked in {year}."`. It produces formatted text using the current values of those expressions.
What do `//` and `%` return?
`7 // 2` gives `3` because `//` performs floor division, while `7 % 2` gives `1`, the remainder after division.
How do `=` and `==` differ?
`=` assigns a value to a name, whereas `==` compares two values and produces a Boolean result such as `True` or `False`.
How does an `if` chain choose a branch?
In an `if`/`elif`/`else` chain, conditions are tested in order and at most one branch runs. The `else` branch runs only when all preceding conditions are false.
Is `range()`'s endpoint included?
The endpoint passed to `range()` is excluded. Therefore, `range(1, 4)` produces `1`, `2`, and `3`.
What causes an infinite `while` loop?
A `while` loop can run forever if its condition never becomes false. The loop body must change relevant state so that termination eventually becomes possible.
How do `break` and `continue` differ?
`break` immediately leaves the nearest loop. `continue` skips the rest of the current iteration and begins the next iteration.
What is the difference between a parameter and an argument?
In `def square(number):`, `number` is a parameter. In `square(6)`, `6` is the argument supplied to that parameter when the function is called.