nesting
Putting one control statement inside another, such as an if inside a for loop, with each level indented further.
In more detail
The inner block runs as part of the outer one: an if inside a loop is tested on every pass. Deep nesting gets hard to read, which is a hint to move the inner part into a function. Data can nest too: lists of lists, dictionaries of lists.
Related terms
- code block — The group of indented statements under a heading such as def, if, for or while, which run together as one unit.
- indentation — The spaces at the start of a line, which in Python decide which statements belong inside a def, if, for or other block.
- for loop — A loop that runs its body once for each item in a list or other collection, setting a loop variable to the current item.
- if statement — A statement that runs a block of code only when a condition holds, optionally with an else block for when it does not.
Taught in
- Input, And Numbers Versus Digits — Hands-on Python: Complete Video Course & Book
- Function Parameters — Hands-on Python: Complete Video Course & Book
- Playing Computer — Hands-on Python: Complete Video Course & Book
- Animation: Loops, Bouncing, Flushing — Hands-on Python: Complete Video Course & Book
- Nesting Control Flow Statements — Hands-on Python: Complete Video Course & Book
- Chapter Three In One Sitting — Hands-on Python: Complete Video Course & Book
- Branching With If, Elif And Else — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- While, For, Range And The Loop Else — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Nested Loops, Traced By Hand — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Control Flow Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Tuples, And The Comma That Makes Them — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions, Return Values And Recursion — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Import Variants, dir() And sys.path — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Your Own Modules And Packages — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Modules Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Object-Oriented Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- List Comprehensions, Filtered And Nested — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep