Physics I / Functions and modular decomposition
Practice question · Put in order

Order the execution when Python runs: result = round(abs(-2.7))

Hints
  1. Nested calls evaluate from the inside out.
  2. Assignment happens last, the right side must be fully computed before the name is bound.
Show the answer
  1. Evaluate the literal −2.7
  2. Call abs, producing 2.7
  3. Call round, producing 3
  4. Bind the name result to 3
Why

Composition runs inside-out: innermost value, inner call, outer call, then the assignment. Reading nested code as a pipeline of values is the fastest way to trace what any expression does.

Read the lesson: Functions and modular decomposition →

Practise Functions and modular decomposition

The app has 11 more questions on this lesson, and keeps your place in the course. Physics I is free to start.

More questions on Functions and modular decomposition