René's URL Explorer Experiment


Title: Control Flow Structures in Python – Real Python

Open Graph Title: Control Flow Structures in Python – Real Python

Description: Take control of your code with Python control flow structures. You'll learn with real examples using loops, conditionals, try-except blocks, and pattern matching.

Open Graph Description: Take control of your code with Python control flow structures. You'll learn with real examples using loops, conditionals, try-except blocks, and pattern matching.

Mail addresses
?subject=Python article for you&body=Control Flow Structures in Python on Real Python https://realpython.com/python-control-flow/

Opengraph URL: https://realpython.com/python-control-flow/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Control Flow Structures in Python",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/Control-Flow-Structures-in-Python_Watermarked-2.333650ffaf49.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/python-control-flow/",
    "lastReviewed": "2025-04-17",
    "author": {
      "@type": "Person",
      "name": "Leodanis Pozo Ramos",
      "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
      "url": "https://realpython.com/team/lpozoramos/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Brenda Weleschuk",
        "image": "https://realpython.com/cdn-cgi/image/width=320,height=320,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_3324_1.50b309355fc1.jpg",
        "url": "https://realpython.com/team/bweleschuk/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Bartosz Zaczy\u0144ski",
        "image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
        "url": "https://realpython.com/team/bzaczynski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Geir Arne Hjelle",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
        "url": "https://realpython.com/team/gahjelle/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2025-05-28T14:00:00+00:00",
  "dateModified": "2025-04-17T14:04:57.733346+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "Leodanis Pozo Ramos",
    "image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
    "url": "https://realpython.com/team/lpozoramos/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "Take control of your code with Python control flow structures. You'll learn with real examples using loops, conditionals, try-except blocks, and pattern matching.",
  "hasPart": {
    "@type": "FAQPage",
    "mainEntity": [
      {
        "@type": "Question",
        "name": "What is control flow in Python?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "

Control flow in Python refers to the order in which code statements are executed or evaluated in your program. You can use control flow structures like conditionals and loops to alter the default sequential execution.

" } }, { "@type": "Question", "name": "What are common control flow statements in Python?", "acceptedAnswer": { "@type": "Answer", "text": "

Common Python control flow statements include conditionals with the if, elif, else keywords, loops with the for and while keywords, and exception handling with tryexcept. You also have pattern matching with matchcase blocks.

" } }, { "@type": "Question", "name": "When should you use flow control structures in Python?", "acceptedAnswer": { "@type": "Answer", "text": "

You should use flow control structures in Python when you need to make decisions, manage branching logic, repeat tasks, or handle errors and exceptions.

" } } ] } }

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/Control-Flow-Structures-in-Python_Watermarked-2.333650ffaf49.jpg
og:imagehttps://files.realpython.com/media/Control-Flow-Structures-in-Python_Watermarked-2.333650ffaf49.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/python-control-flow/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/python-control-flow/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Tutorial Writerhttps://realpython.com/write-for-us/
Become a Video Instructorhttps://realpython.com/become-an-instructor/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Fpython-control-flow%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/python-control-flow/#toc
Getting to Know Control Flow in Pythonhttps://realpython.com/python-control-flow/#getting-to-know-control-flow-in-python
Using Conditional Statementshttps://realpython.com/python-control-flow/#using-conditional-statements
Using if to Make Decisionshttps://realpython.com/python-control-flow/#using-if-to-make-decisions
Nesting Conditionals and Using Boolean Operatorshttps://realpython.com/python-control-flow/#nesting-conditionals-and-using-boolean-operators
Chaining Multiple Conditions With elifhttps://realpython.com/python-control-flow/#chaining-multiple-conditions-with-elif
Running a Default Code Block With elsehttps://realpython.com/python-control-flow/#running-a-default-code-block-with-else
Conditional Expressionshttps://realpython.com/python-control-flow/#conditional-expressions
Repeating Code With for and while Loopshttps://realpython.com/python-control-flow/#repeating-code-with-for-and-while-loops
The for Loop to Traverse Iterableshttps://realpython.com/python-control-flow/#the-for-loop-to-traverse-iterables
The while Loop for Conditional Iterationhttps://realpython.com/python-control-flow/#the-while-loop-for-conditional-iteration
The break and continue Statementshttps://realpython.com/python-control-flow/#the-break-and-continue-statements
The else Clause in Loopshttps://realpython.com/python-control-flow/#the-else-clause-in-loops
Nested Loopshttps://realpython.com/python-control-flow/#nested-loops
Comprehensionshttps://realpython.com/python-control-flow/#comprehensions
Repeating Code Through Recursionhttps://realpython.com/python-control-flow/#repeating-code-through-recursion
Exploring Other Structures Related to Control Flowhttps://realpython.com/python-control-flow/#exploring-other-structures-related-to-control-flow
The return Statementhttps://realpython.com/python-control-flow/#the-return-statement
The yield Statementhttps://realpython.com/python-control-flow/#the-yield-statement
The raise Statementhttps://realpython.com/python-control-flow/#the-raise-statement
The with Statementhttps://realpython.com/python-control-flow/#the-with-statement
Using try … except Blocks to Control Flowhttps://realpython.com/python-control-flow/#using-try-except-blocks-to-control-flow
Handling Errors With try … except Blockshttps://realpython.com/python-control-flow/#handling-errors-with-try-except-blocks
Running Post-Success Code With the else Clausehttps://realpython.com/python-control-flow/#running-post-success-code-with-the-else-clause
Cleaning Up With the finally Clausehttps://realpython.com/python-control-flow/#cleaning-up-with-the-finally-clause
Matching Patterns With match … casehttps://realpython.com/python-control-flow/#matching-patterns-with-match-case
Common Pitfalls and Best Practiceshttps://realpython.com/python-control-flow/#common-pitfalls-and-best-practices
Unintentional Infinite Loopshttps://realpython.com/python-control-flow/#unintentional-infinite-loops
Always True or False Conditionshttps://realpython.com/python-control-flow/#always-true-or-false-conditions
Wrong Order of Conditionshttps://realpython.com/python-control-flow/#wrong-order-of-conditions
Too Broad Exceptionshttps://realpython.com/python-control-flow/#too-broad-exceptions
Hard-to-Read Nested Constructshttps://realpython.com/python-control-flow/#hard-to-read-nested-constructs
Conclusionhttps://realpython.com/python-control-flow/#conclusion
Frequently Asked Questionshttps://realpython.com/python-control-flow/#frequently-asked-questions
https://realpython.com/feedback/survey/article/python-control-flow/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/python-control-flow/disliked/?from=article-sidebar
Leodanis Pozo Ramoshttps://realpython.com/python-control-flow/#author
https://realpython.com/python-control-flow/#reader-comments
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
Getting to Know Control Flow in Pythonhttps://realpython.com/python-control-flow/#getting-to-know-control-flow-in-python
Using Conditional Statementshttps://realpython.com/python-control-flow/#using-conditional-statements
Using if to Make Decisionshttps://realpython.com/python-control-flow/#using-if-to-make-decisions
Nesting Conditionals and Using Boolean Operatorshttps://realpython.com/python-control-flow/#nesting-conditionals-and-using-boolean-operators
Chaining Multiple Conditions With elifhttps://realpython.com/python-control-flow/#chaining-multiple-conditions-with-elif
Running a Default Code Block With elsehttps://realpython.com/python-control-flow/#running-a-default-code-block-with-else
Conditional Expressionshttps://realpython.com/python-control-flow/#conditional-expressions
Repeating Code With for and while Loopshttps://realpython.com/python-control-flow/#repeating-code-with-for-and-while-loops
The for Loop to Traverse Iterableshttps://realpython.com/python-control-flow/#the-for-loop-to-traverse-iterables
The while Loop for Conditional Iterationhttps://realpython.com/python-control-flow/#the-while-loop-for-conditional-iteration
The break and continue Statementshttps://realpython.com/python-control-flow/#the-break-and-continue-statements
The else Clause in Loopshttps://realpython.com/python-control-flow/#the-else-clause-in-loops
Nested Loopshttps://realpython.com/python-control-flow/#nested-loops
Comprehensionshttps://realpython.com/python-control-flow/#comprehensions
Repeating Code Through Recursionhttps://realpython.com/python-control-flow/#repeating-code-through-recursion
Exploring Other Structures Related to Control Flowhttps://realpython.com/python-control-flow/#exploring-other-structures-related-to-control-flow
The return Statementhttps://realpython.com/python-control-flow/#the-return-statement
The yield Statementhttps://realpython.com/python-control-flow/#the-yield-statement
The raise Statementhttps://realpython.com/python-control-flow/#the-raise-statement
The with Statementhttps://realpython.com/python-control-flow/#the-with-statement
Using try … except Blocks to Control Flowhttps://realpython.com/python-control-flow/#using-try-except-blocks-to-control-flow
Handling Errors With try … except Blockshttps://realpython.com/python-control-flow/#handling-errors-with-try-except-blocks
Running Post-Success Code With the else Clausehttps://realpython.com/python-control-flow/#running-post-success-code-with-the-else-clause
Cleaning Up With the finally Clausehttps://realpython.com/python-control-flow/#cleaning-up-with-the-finally-clause
Matching Patterns With match … casehttps://realpython.com/python-control-flow/#matching-patterns-with-match-case
Common Pitfalls and Best Practiceshttps://realpython.com/python-control-flow/#common-pitfalls-and-best-practices
Unintentional Infinite Loopshttps://realpython.com/python-control-flow/#unintentional-infinite-loops
Always True or False Conditionshttps://realpython.com/python-control-flow/#always-true-or-false-conditions
Wrong Order of Conditionshttps://realpython.com/python-control-flow/#wrong-order-of-conditions
Too Broad Exceptionshttps://realpython.com/python-control-flow/#too-broad-exceptions
Hard-to-Read Nested Constructshttps://realpython.com/python-control-flow/#hard-to-read-nested-constructs
Conclusionhttps://realpython.com/python-control-flow/#conclusion
Frequently Asked Questionshttps://realpython.com/python-control-flow/#frequently-asked-questions
Remove adshttps://realpython.com/account/join/
Click here to download the free sample codehttps://realpython.com/bonus/python-control-flow-code/
https://realpython.com/quizzes/python-control-flow/
Control Flow Structures in Pythonhttps://realpython.com/quizzes/python-control-flow/
https://realpython.com/python-control-flow/#getting-to-know-control-flow-in-python
control flowhttps://realpython.com/ref/glossary/control-flow/
statementshttps://realpython.com/ref/glossary/statement/
conditionalshttps://realpython.com/python-conditional-statements/
loopshttps://realpython.com/ref/glossary/loop/
maintainabilityhttps://realpython.com/python-code-quality/#maintainability
for loophttps://realpython.com/python-for-loop/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#using-conditional-statements
Conditional Statements in Pythonhttps://realpython.com/python-conditional-statements/
https://realpython.com/python-control-flow/#using-if-to-make-decisions
ifhttps://realpython.com/ref/keywords/if/
https://realpython.com/python-control-flow/#nesting-conditionals-and-using-boolean-operators
Booleanhttps://realpython.com/python-boolean/
andhttps://realpython.com/ref/keywords/and/
Zen of Python’shttps://realpython.com/zen-of-python/
operator chaininghttps://realpython.com/python-boolean/#chaining-comparison-operators
Booleanhttps://realpython.com/ref/glossary/boolean/
Using the “and” Boolean Operator in Pythonhttps://realpython.com/python-and-operator/
Using the “or” Boolean Operator in Pythonhttps://realpython.com/python-or-operator/
Using the “not” Boolean Operator in Pythonhttps://realpython.com/python-not-operator/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#chaining-multiple-conditions-with-elif
elifhttps://realpython.com/ref/keywords/elif/
mutually exclusivehttps://en.wikipedia.org/wiki/Mutual_exclusivity
https://realpython.com/python-control-flow/#running-a-default-code-block-with-else
elsehttps://realpython.com/ref/keywords/else/
syntax errorhttps://realpython.com/ref/builtin-exceptions/syntaxerror/
modulo operatorhttps://realpython.com/python-modulo-operator/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#conditional-expressions
conditional expressionshttps://realpython.com/python-operators-expressions/#conditional-expressions-or-the-ternary-operator
Chttps://realpython.com/c-for-python-programmers/
https://realpython.com/python-control-flow/#repeating-code-with-for-and-while-loops
for loopshttps://realpython.com/python-for-loop/
while loopshttps://realpython.com/python-while-loop/
forhttps://en.wikipedia.org/wiki/For_loop
whilehttps://en.wikipedia.org/wiki/While_loop
breakhttps://realpython.com/python-break/
continuehttps://realpython.com/python-continue/
https://realpython.com/python-control-flow/#the-for-loop-to-traverse-iterables
foreach loophttps://en.wikipedia.org/wiki/Foreach_loop
for keywordhttps://realpython.com/python-keywords/#the-for-keyword
iterationhttps://realpython.com/ref/glossary/iteration/
listshttps://realpython.com/python-list/
tupleshttps://realpython.com/python-tuple/
stringshttps://realpython.com/python-strings/
dictionarieshttps://realpython.com/python-dicts/
setshttps://realpython.com/python-sets/
iterablehttps://realpython.com/python-iterators-iterables/
Python for Loops: The Pythonic Wayhttps://realpython.com/python-for-loop/
print()https://realpython.com/python-print/
Asynchronous Iterators and Iterables in Pythonhttps://realpython.com/python-async-iterators/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#the-while-loop-for-conditional-iteration
GUI applicationshttps://realpython.com/python-pyqt-gui-calculator/
asynchronoushttps://realpython.com/ref/glossary/asynchronous-programming/
Python while Loops: Repeating Tasks Conditionallyhttps://realpython.com/python-while-loop/
while keywordhttps://realpython.com/python-keywords/#the-while-keyword
How Can You Emulate Do-While Loops in Python?https://realpython.com/python-do-while/
KeyboardInterrupthttps://realpython.com/python-built-in-exceptions/#keyboardinterrupt
https://realpython.com/python-control-flow/#the-break-and-continue-statements
breakhttps://realpython.com/ref/keywords/break/
continuehttps://realpython.com/ref/keywords/continue/
linterhttps://realpython.com/ref/glossary/linter/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#the-else-clause-in-loops
else keywordhttps://realpython.com/python-keywords/#the-else-keyword
https://realpython.com/python-control-flow/#nested-loops
Nested Loops in Pythonhttps://realpython.com/nested-loops-python/
time complexityhttps://en.wikipedia.org/wiki/Time_complexity
https://realpython.com/python-control-flow/#comprehensions
Comprehensionshttps://realpython.com/ref/glossary/comprehension/
When to Use a List Comprehension in Pythonhttps://realpython.com/list-comprehension-python/
Python Set Comprehensions: How and When to Use Themhttps://realpython.com/python-set-comprehension/
Python Dictionary Comprehensions: How and When to Use Themhttps://realpython.com/python-dictionary-comprehension/
string manipulation methodshttps://realpython.com/python-strings/#exploring-str-class-methods
.strip()https://realpython.com/python-strip/
.lower()https://realpython.com/python-strings/#lower
Sets in Pythonhttps://realpython.com/python-sets/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#repeating-code-through-recursion
Recursion in Python: An Introductionhttps://realpython.com/python-recursion/
Thinking Recursively in Pythonhttps://realpython.com/python-thinking-recursively/
file systemshttps://realpython.com/working-with-files-in-python/
JSONhttps://realpython.com/python-json/
RecursionErrorhttps://realpython.com/python-built-in-exceptions/#recursionerror
call stackhttps://en.wikipedia.org/wiki/Call_stack
https://realpython.com/python-control-flow/#exploring-other-structures-related-to-control-flow
https://realpython.com/python-control-flow/#the-return-statement
returnhttps://realpython.com/ref/keywords/return/
The Python return Statement: Usage and Best Practiceshttps://realpython.com/python-return-statement/
Python coding interviewhttps://realpython.com/python-practice-problems/
FizzBuzzhttps://en.wikipedia.org/wiki/Fizz_buzz#Programming
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#the-yield-statement
yieldhttps://realpython.com/ref/keywords/yield/
generatorhttps://realpython.com/ref/glossary/generator/
How to Use Generators and yield in Pythonhttps://realpython.com/introduction-to-python-generators/
next()https://realpython.com/python-built-in-functions/#building-and-consuming-iterators-iter-and-next
https://realpython.com/python-control-flow/#the-raise-statement
raisehttps://realpython.com/ref/keywords/raise/
Python’s raise: Effectively Raising Exceptions in Your Codehttps://realpython.com/python-raise-exception/
ValueErrorhttps://realpython.com/python-built-in-exceptions/#valueerror
https://realpython.com/python-control-flow/#the-with-statement
withhttps://realpython.com/ref/keywords/with/
context managerhttps://realpython.com/ref/glossary/context-manager/
Context Managers and Python’s with Statementhttps://realpython.com/python-with-statement/
open()https://realpython.com/python-built-in-functions/#opening-files-open
open()https://realpython.com/ref/builtin-functions/open/
as keywordhttps://realpython.com/python-keywords/#the-as-keyword-used-with-with
closing the filehttps://realpython.com/why-close-file-python/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#using-try-except-blocks-to-control-flow
exceptionshttps://realpython.com/python-exceptions/
EAFPhttps://realpython.com/python-lbyl-vs-eafp/#the-easier-to-ask-forgiveness-than-permission-eafp-style
LBYLhttps://realpython.com/python-lbyl-vs-eafp/#the-look-before-you-leap-lbyl-style
https://realpython.com/python-control-flow/#handling-errors-with-try-except-blocks
try keywordhttps://realpython.com/python-keywords/#the-try-keyword
excepthttps://realpython.com/ref/keywords/except/
OSErrorhttps://realpython.com/ref/builtin-exceptions/oserror/
tuplehttps://realpython.com/ref/builtin-types/tuple/
parentheses are optionalhttps://realpython.com/python-news-april-2025/#pep-758-parenthesized-exceptions-accepted
int()https://realpython.com/python-built-in-functions/#representing-integer-numbers-int-bin-oct-and-hex
ValueErrorhttps://realpython.com/ref/builtin-exceptions/valueerror/
TypeErrorhttps://realpython.com/ref/builtin-exceptions/typeerror/
Nonehttps://realpython.com/null-in-python/
int()https://realpython.com/ref/builtin-types/int/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#running-post-success-code-with-the-else-clause
inputhttps://realpython.com/python-keyboard-input/
input into an integerhttps://realpython.com/python-input-integer/
https://realpython.com/python-control-flow/#cleaning-up-with-the-finally-clause
finallyhttps://realpython.com/ref/keywords/finally/
APIhttps://realpython.com/python-api/
os.environhttps://docs.python.org/3/library/os.html#os.environ
mappinghttps://realpython.com/ref/glossary/mapping/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-control-flow/#matching-patterns-with-match-case
Structural Pattern Matching in Pythonhttps://realpython.com/structural-pattern-matching/
abstract syntax trees (AST)https://en.wikipedia.org/wiki/Abstract_syntax_tree
JSONhttps://realpython.com/python-json/
CSVhttps://realpython.com/python-csv/
pathlib.Pathhttps://realpython.com/python-pathlib/
https://realpython.com/python-control-flow/#common-pitfalls-and-best-practices
https://realpython.com/python-control-flow/#unintentional-infinite-loops
GUI (graphical user interface)https://realpython.com/python-pyqt-gui-calculator/
asynchronous codehttps://realpython.com/async-io-python/
https://realpython.com/python-control-flow/#always-true-or-false-conditions
https://realpython.com/python-control-flow/#wrong-order-of-conditions
FizzBuzzhttps://en.wikipedia.org/wiki/Fizz_buzz#Programming
https://realpython.com/python-control-flow/#too-broad-exceptions
tracebackshttps://realpython.com/python-traceback/
https://realpython.com/python-control-flow/#hard-to-read-nested-constructs
https://realpython.com/python-control-flow/#conclusion
Click here to download the free sample codehttps://realpython.com/bonus/python-control-flow-code/
https://realpython.com/python-control-flow/#frequently-asked-questions
https://realpython.com/quizzes/python-control-flow/
Control Flow Structures in Pythonhttps://realpython.com/quizzes/python-control-flow/
https://realpython.com/feedback/survey/article/python-control-flow/liked/?from=article-footer
https://realpython.com/feedback/survey/article/python-control-flow/disliked/?from=article-footer
https://realpython.com/team/lpozoramos/
» More about Leodanishttps://realpython.com/team/lpozoramos/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/bweleschuk/
Brendahttps://realpython.com/team/bweleschuk/
https://realpython.com/team/bzaczynski/
Bartoszhttps://realpython.com/team/bzaczynski/
https://realpython.com/team/gahjelle/
Geir Arnehttps://realpython.com/team/gahjelle/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-control-flow
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-control-flow
https://realpython.com/feedback/survey/article/python-control-flow/liked/?from=article-comments
https://realpython.com/feedback/survey/article/python-control-flow/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fpython-control-flow%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20Control%20Flow%20Structures%20in%20Python&url=https%3A%2F%2Frealpython.com%2Fpython-control-flow%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20Control%20Flow%20Structures%20in%20Python%20https%3A%2F%2Frealpython.com%2Fpython-control-flow%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fpython-control-flow%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
intermediatehttps://realpython.com/tutorials/intermediate/
pythonhttps://realpython.com/tutorials/python/
Defining Your Own Python Functionhttps://realpython.com/defining-your-own-python-function/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-control-flow
How Can You Structure Your Python Script?https://realpython.com/python-script-structure/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-control-flow
Conditional Statements in Pythonhttps://realpython.com/python-conditional-statements/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-control-flow
Object-Oriented Programming (OOP) in Pythonhttps://realpython.com/python3-object-oriented-programming/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-control-flow
How to Build a Personal Python Learning Roadmaphttps://realpython.com/build-python-learning-roadmap/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-control-flow
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-control-flow%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-control-flow%2F
Sign-Inhttps://realpython.com/account/login/?next=/python-control-flow/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.