Real Python
  • Start Here
  • Learn Python
    Start Learning
    Your Learning Plan →Your personalized Python learning plan Python Tutorials →In-depth articles and video courses Learning Paths →Guided study plans for accelerated learning
    Practice
    Quizzes & Exercises →Check your learning progress Browse Topics →Focus on a specific area or skill level Reference →Concise definitions for common Python terms
    Get Help
    Code Mentor →BetaPersonalized code assistance & learning tools Office Hours →Live Q&A calls with Python experts Community Chat →Learn with other Pythonistas
    Go Deeper
    Live Courses →Live, instructor-led Python courses Books →Round out your knowledge and learn offline Podcast →Hear what’s new in the world of Python
    Unlock All Content and Become a Python Expert →Get unlimited access to all Real Python has to offer
    Unlock All Content →Become a Python Expert
  • More
    Learner Stories Python Newsletter Python Job Board Meet the Team Become a Contributor
  • Search
/
  • Join
  • Sign‑In

— FREE Email Series —

🐍 Python Tricks 💌

Python Tricks Dictionary Merge

🔒 No spam. Unsubscribe any time.

Browse Topics Guided Learning Paths
Basics Intermediate Advanced
ai algorithms api best-practices career community databases data-science data-structures data-viz devops django docker editors flask front-end gamedev gui machine-learning news numpy projects python stdlib testing tools web-dev web-scraping

Table of Contents

  • Getting Started With the Python for Loop
  • Traversing Built-in Collections in Python
    • Sequences: Lists, Tuples, Strings, and Ranges
    • Collections: Dictionaries and Sets
  • Using Advanced for Loop Syntax
    • The break Statement
    • The continue Statement
    • The else Clause
    • Nested for Loops
  • Exploring Pythonic Looping Techniques
    • Iterating With Indices: The Pythonic Way
    • Looping Over Several Iterables in Parallel
    • Iterating Over Multiple Iterables Sequentially
    • Repeating Actions a Predefined Number of Times
    • Iterating Over Reversed and Sorted Iterables
  • Understanding Common Pitfalls in for Loops
    • Modifying the Loop Collection
    • Changing the Loop Variable
    • Ignoring Possible Exceptions
  • Using for Loops vs Comprehensions
  • Using async for Loops for Asynchronous Iteration
  • Conclusion
  • Frequently Asked Questions