René's URL Explorer Experiment


Title: The Python return Statement: Usage and Best Practices – Real Python

Open Graph Title: The Python return Statement: Usage and Best Practices – Real Python

Description: See how Python return values work, including multiple results, so you write clear, testable functions. Follow examples and practice as you go.

Open Graph Description: See how Python return values work, including multiple results, so you write clear, testable functions. Follow examples and practice as you go.

Mail addresses
?subject=Python article for you&body=The Python return Statement: Usage and Best Practices on Real Python https://realpython.com/python-return-statement/

Opengraph URL: https://realpython.com/python-return-statement/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "The Python return Statement: Usage and Best Practices",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/The-Python-return-Statement_Watermarked.42392feb6973.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/python-return-statement/",
    "lastReviewed": "2024-06-14",
    "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": "Bryan Weber",
        "image": "https://realpython.com/cdn-cgi/image/width=1000,height=1000,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/BryanWeber-square.789781f1e92c.jpg",
        "url": "https://realpython.com/team/bweber/",
        "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": "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"
        }
      },
      {
        "@type": "Person",
        "name": "Joanna Jablonski",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/jjablonksi-avatar.e37c4f83308e.jpg",
        "url": "https://realpython.com/team/jjablonski/",
        "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": "Jacob Schmitt",
        "image": "https://realpython.com/cdn-cgi/image/width=400,height=400,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/profile-small_js.2f4d0d8da1ca.jpg",
        "url": "https://realpython.com/team/jschmitt/",
        "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": "2020-09-28T14:00:00+00:00",
  "dateModified": "2024-06-14T10:33:51.542014+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": "See how Python return values work, including multiple results, so you write clear, testable functions. Follow examples and practice as you go.",
  "hasPart": {
    "@type": "FAQPage",
    "mainEntity": [
      {
        "@type": "Question",
        "name": "What\u2019s the difference between explicit and implicit return statements?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "

An explicit return statement immediately ends the function’s execution and sends the specified value back to the caller. For example, a function can return a number, a list, or any other object. If no return statement is present, Python adds one implicitly, which returns None.

" } }, { "@type": "Question", "name": "How do I return single or multiple values from my functions to the caller code?", "acceptedAnswer": { "@type": "Answer", "text": "

In Python, the return statement allows you to send values back to the caller from a function. To return a single value, use the return keyword followed by the value. This can be any data type, such as a number, string, list, or object.

\n

To return multiple values, list them after the return keyword separated by commas. Python packs these values into a tuple. You can then unpack the tuple into separate variables or store it as a single variable.

" } }, { "@type": "Question", "name": "What are the best practices I should apply when using the return statement?", "acceptedAnswer": { "@type": "Answer", "text": "

First, explicitly return None when appropriate. If your function should return None, do so explicitly with return None for clarity. However, if your function performs actions without a clear return value, you can omit the return statement and rely on Python implicitly returning None.

\n

Additionally, avoid complex return expressions. Instead, break them down to improve readability and debugging. You can also use short-circuiting in loops to simplify your code. Employ return statements inside loops to exit early when a condition is met, saving processing time.

\n

You should also prefer self-contained functions over those that modify global variables, and when using conditional returns, handle all possible conditions with appropriate return statements to avoid hidden bugs.

" } }, { "@type": "Question", "name": "How do I code a closure factory function?", "acceptedAnswer": { "@type": "Answer", "text": "

Creating a closure factory function involves making a function that returns another function. This inner function retains access to the variables from the outer function. It\u2019s perfect for situations where you want to keep some state information between calls.

" } }, { "@type": "Question", "name": "How do I code a decorator function?", "acceptedAnswer": { "@type": "Answer", "text": "

For decorator functions, you write a function that takes another function, adds some extra functionality, and returns this new function. Decorators are great for tasks like logging and timing that aren\u2019t central to the original function\u2019s purpose.

" } } ] } }

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/The-Python-return-Statement_Watermarked.42392feb6973.jpg
og:imagehttps://files.realpython.com/media/The-Python-return-Statement_Watermarked.42392feb6973.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/python-return-statement/
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-return-statement/
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-return-statement%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-return-statement/#toc
Getting Started With Python Functionshttps://realpython.com/python-return-statement/#getting-started-with-python-functions
Understanding the Python return Statementhttps://realpython.com/python-return-statement/#understanding-the-python-return-statement
Explicit return Statementshttps://realpython.com/python-return-statement/#explicit-return-statements
Implicit return Statementshttps://realpython.com/python-return-statement/#implicit-return-statements
Returning vs Printinghttps://realpython.com/python-return-statement/#returning-vs-printing
Returning Multiple Valueshttps://realpython.com/python-return-statement/#returning-multiple-values
Using the Python return Statement: Best Practiceshttps://realpython.com/python-return-statement/#using-the-python-return-statement-best-practices
Returning None Explicitlyhttps://realpython.com/python-return-statement/#returning-none-explicitly
Remembering the Return Valuehttps://realpython.com/python-return-statement/#remembering-the-return-value
Avoiding Complex Expressionshttps://realpython.com/python-return-statement/#avoiding-complex-expressions
Returning Values vs Modifying Globalshttps://realpython.com/python-return-statement/#returning-values-vs-modifying-globals
Using return With Conditionalshttps://realpython.com/python-return-statement/#using-return-with-conditionals
Returning True or Falsehttps://realpython.com/python-return-statement/#returning-true-or-false
Short-Circuiting Loopshttps://realpython.com/python-return-statement/#short-circuiting-loops
Recognizing Dead Codehttps://realpython.com/python-return-statement/#recognizing-dead-code
Returning Multiple Named-Objectshttps://realpython.com/python-return-statement/#returning-multiple-named-objects
Returning Functions: Closureshttps://realpython.com/python-return-statement/#returning-functions-closures
Taking and Returning Functions: Decoratorshttps://realpython.com/python-return-statement/#taking-and-returning-functions-decorators
Returning User-Defined Objects: The Factory Patternhttps://realpython.com/python-return-statement/#returning-user-defined-objects-the-factory-pattern
Using return in try … finally Blockshttps://realpython.com/python-return-statement/#using-return-in-try-finally-blocks
Using return in Generator Functionshttps://realpython.com/python-return-statement/#using-return-in-generator-functions
FAQshttps://realpython.com/python-return-statement/#faqs
https://realpython.com/feedback/survey/article/python-return-statement/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/python-return-statement/disliked/?from=article-sidebar
Using the Python return Statement Effectivelyhttps://realpython.com/courses/effective-python-return-statement/
Leodanis Pozo Ramoshttps://realpython.com/python-return-statement/#author
https://realpython.com/python-return-statement/#reader-comments
basicshttps://realpython.com/tutorials/basics/
best-practiceshttps://realpython.com/tutorials/best-practices/
pythonhttps://realpython.com/tutorials/python/
Getting Started With Python Functionshttps://realpython.com/python-return-statement/#getting-started-with-python-functions
Understanding the Python return Statementhttps://realpython.com/python-return-statement/#understanding-the-python-return-statement
Explicit return Statementshttps://realpython.com/python-return-statement/#explicit-return-statements
Implicit return Statementshttps://realpython.com/python-return-statement/#implicit-return-statements
Returning vs Printinghttps://realpython.com/python-return-statement/#returning-vs-printing
Returning Multiple Valueshttps://realpython.com/python-return-statement/#returning-multiple-values
Using the Python return Statement: Best Practiceshttps://realpython.com/python-return-statement/#using-the-python-return-statement-best-practices
Returning None Explicitlyhttps://realpython.com/python-return-statement/#returning-none-explicitly
Remembering the Return Valuehttps://realpython.com/python-return-statement/#remembering-the-return-value
Avoiding Complex Expressionshttps://realpython.com/python-return-statement/#avoiding-complex-expressions
Returning Values vs Modifying Globalshttps://realpython.com/python-return-statement/#returning-values-vs-modifying-globals
Using return With Conditionalshttps://realpython.com/python-return-statement/#using-return-with-conditionals
Returning True or Falsehttps://realpython.com/python-return-statement/#returning-true-or-false
Short-Circuiting Loopshttps://realpython.com/python-return-statement/#short-circuiting-loops
Recognizing Dead Codehttps://realpython.com/python-return-statement/#recognizing-dead-code
Returning Multiple Named-Objectshttps://realpython.com/python-return-statement/#returning-multiple-named-objects
Returning Functions: Closureshttps://realpython.com/python-return-statement/#returning-functions-closures
Taking and Returning Functions: Decoratorshttps://realpython.com/python-return-statement/#taking-and-returning-functions-decorators
Returning User-Defined Objects: The Factory Patternhttps://realpython.com/python-return-statement/#returning-user-defined-objects-the-factory-pattern
Using return in try … finally Blockshttps://realpython.com/python-return-statement/#using-return-in-try-finally-blocks
Using return in Generator Functionshttps://realpython.com/python-return-statement/#using-return-in-generator-functions
FAQshttps://realpython.com/python-return-statement/#faqs
Remove adshttps://realpython.com/account/join/
Using the Python return Statement Effectivelyhttps://realpython.com/courses/effective-python-return-statement/
return statementhttps://en.wikipedia.org/wiki/Return_statement
functionhttps://realpython.com/defining-your-own-python-function/
methodhttps://realpython.com/python3-object-oriented-programming/#instance-methods
returnhttps://realpython.com/ref/keywords/return/
Pythonichttps://realpython.com/learning-paths/writing-pythonic-code/
Defining Your Own Python Functionhttps://realpython.com/defining-your-own-python-function/
5 Thoughts On Python Masteryhttps://realpython.com/bonus/python-mastery-course/
https://realpython.com/quizzes/the-python-return-statement/
The Python return Statementhttps://realpython.com/quizzes/the-python-return-statement/
https://realpython.com/python-return-statement/#getting-started-with-python-functions
subroutineshttps://en.wikipedia.org/wiki/Subroutine
Visual Basichttps://en.wikipedia.org/wiki/Visual_Basic
functionshttps://realpython.com/defining-your-own-python-function/
argumentshttps://docs.python.org/3/glossary.html#term-argument
Sourcehttps://docs.python.org/3/glossary.html#term-function
def keywordhttps://realpython.com/defining-your-own-python-function/
indentationhttps://docs.python.org/3/reference/lexical_analysis.html#indentation
pass statementhttps://realpython.com/python-pass/
Defining Your Own Python Functionhttps://realpython.com/defining-your-own-python-function/
Python return statementhttps://docs.python.org/3/reference/simple_stmts.html#grammar-token-return_stmt
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#understanding-the-python-return-statement
methodhttps://realpython.com/python3-object-oriented-programming/#instance-methods
return keywordhttps://realpython.com/python-keywords/#returning-keywords-return-yield
inthttps://docs.python.org/3/library/functions.html#int
floathttps://docs.python.org/3/library/functions.html#float
complexhttps://docs.python.org/3/library/functions.html#complex
listhttps://realpython.com/python-list/
tuplehttps://realpython.com/courses/lists-tuples-python/
dictionaryhttps://realpython.com/courses/lists-tuples-python/
sethttps://realpython.com/courses/sets-python/
modules or packageshttps://realpython.com/courses/python-modules-packages/
Nonehttps://realpython.com/null-in-python/
https://realpython.com/python-return-statement/#explicit-return-statements
SyntaxErrorhttps://realpython.com/invalid-syntax-python/
Regular methods, class methods, and static methodshttps://realpython.com/instance-class-and-static-methods-demystified/
Python classeshttps://realpython.com/python-classes/
stringshttps://realpython.com/python-strings/
classes, instanceshttps://realpython.com/python3-object-oriented-programming/#classes-vs-instances
list comprehensionhttps://realpython.com/courses/using-list-comprehensions-effectively/
expressionhttps://realpython.com/python-operators-expressions/
expressionshttps://docs.python.org/3/glossary.html#term-expression
statementshttps://docs.python.org/3/glossary.html#term-statement
conditionalshttps://realpython.com/courses/python-conditional-statements/
loopshttps://realpython.com/courses/how-to-write-pythonic-loops/
sum()https://realpython.com/python-sum-function/
len()https://realpython.com/len-python-function/
variablehttps://realpython.com/python-variables/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#implicit-return-statements
print()https://realpython.com/python-print/
Python interpreterhttps://realpython.com/lessons/overview-python-interpreter/
interactive sessionhttps://realpython.com/run-python-scripts/#how-to-run-python-code-interactively
https://realpython.com/python-return-statement/#returning-vs-printing
run it from your command linehttps://realpython.com/run-python-scripts/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#returning-multiple-values
statisticshttps://docs.python.org/3/library/statistics.html
How to Use Type Hints for Multiple Return Types in Pythonhttps://realpython.com/python-type-hints-multiple-types/
iterable unpackinghttps://realpython.com/lessons/tuple-assignment-packing-unpacking/
variableshttps://realpython.com/courses/variables-python/
assigninghttps://realpython.com/python-assignment-operator/
divmod()https://docs.python.org/3/library/functions.html#divmod
https://realpython.com/python-return-statement/#using-the-python-return-statement-best-practices
https://realpython.com/python-return-statement/#returning-none-explicitly
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#remembering-the-return-value
understand and debughttps://realpython.com/python-debug-idle/
debugginghttps://realpython.com/python-debugging-pdb/
https://realpython.com/python-return-statement/#avoiding-complex-expressions
variancehttps://en.wikipedia.org/wiki/Variance
https://realpython.com/python-return-statement/#returning-values-vs-modifying-globals
side effectshttps://realpython.com/defining-your-own-python-function/#side-effects
global variablehttps://realpython.com/python-scope-legb-rule/#modules-the-global-scope
writing some text to a filehttps://realpython.com/read-write-files-python/#reading-and-writing-opened-files
testhttps://realpython.com/pytest-python-testing/
global statementhttps://realpython.com/python-scope-legb-rule/#the-global-statement
Test-Driven Development With PyTesthttps://realpython.com/courses/test-driven-development-pytest/
Using and Creating Global Variables in Your Python Functionshttps://realpython.com/python-use-global-variable-in-function/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#using-return-with-conditionals
conditional statementshttps://realpython.com/courses/python-conditional-statements/
absolute valuehttps://realpython.com/python-absolute-value
if statementhttps://realpython.com/python-conditional-statements/
Pythonichttps://realpython.com/learning-paths/writing-pythonic-code/
abs()https://docs.python.org/3/library/functions.html#abs
https://realpython.com/python-return-statement/#returning-true-or-false
predicatehttps://en.wikipedia.org/wiki/Predicate_(mathematical_logic)
Boolean-valuedhttps://en.wikipedia.org/wiki/Boolean-valued_function
falsyhttps://realpython.com/python-data-types/#boolean-type-boolean-context-and-truthiness
not operatorhttps://realpython.com/python-operators-expressions/#logical-operators
The comparison operatorshttps://realpython.com/python-operators-expressions/#comparison-operators
The membership operatorhttps://docs.python.org/3/reference/expressions.html#membership-test-operations
The identity operatorhttps://realpython.com/python-operators-expressions/#identity-operators
The Boolean operatorhttps://docs.python.org/3/reference/expressions.html#not
Boolean expressionhttps://realpython.com/python-boolean/
considered falsyhttps://docs.python.org/3/library/stdtypes.html#truth-value-testing
Constantshttps://realpython.com/python-constants/
Nonehttps://realpython.com/null-in-python/
Decimal(0)https://docs.python.org/3/library/decimal.html#decimal.Decimal
Fraction(0, 1)https://docs.python.org/3/library/fractions.html#fractions.Fraction
set()https://realpython.com/python-sets/
__bool__()https://docs.python.org/3/reference/datamodel.html#object.__bool__
__len__()https://docs.python.org/3/reference/datamodel.html#object.__len__
orhttps://realpython.com/python-or-operator/
andhttps://realpython.com/python-keywords/#operator-keywords-and-or-not-in-is
bool()https://docs.python.org/3/library/functions.html#bool
if statementhttps://realpython.com/lessons/if-statements/
conditional expression (ternary operator)https://realpython.com/python-conditional-statements/#conditional-expressions-pythons-ternary-operator
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#short-circuiting-loops
any()https://realpython.com/any-python/
https://realpython.com/python-return-statement/#recognizing-dead-code
https://realpython.com/python-return-statement/#returning-multiple-named-objects
collections.namedtuplehttps://realpython.com/python-namedtuple/
dot notationhttps://docs.python.org/3/reference/expressions.html#attribute-references
indexing operationhttps://docs.python.org/3/library/stdtypes.html#common-sequence-operations
namedtuplehttps://realpython.com/python-namedtuple/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#returning-functions-closures
first-class objectshttps://realpython.com/primer-on-python-decorators/#first-class-objects
higher-order functionhttp://en.wikipedia.org/wiki/Higher-order_function
closure factory functionhttps://realpython.com/inner-functions-what-are-they-good-for/#closures-and-factory-functions
inner functionhttps://realpython.com/inner-functions-what-are-they-good-for/
lazy or delayed evaluationhttps://en.wikipedia.org/wiki/Lazy_evaluation
lambda functionhttps://realpython.com/python-lambda/
https://realpython.com/python-return-statement/#taking-and-returning-functions-decorators
decorator functionshttps://realpython.com/primer-on-python-decorators/
importhttps://realpython.com/absolute-vs-relative-python-imports/
time()https://docs.python.org/3/library/time.html#time.time
timehttps://docs.python.org/3/library/time.html
epochhttps://docs.python.org/3/library/time.html#epoch
time.sleep()https://docs.python.org/3/library/time.html#time.sleep
Python sleep(): How to Add Time Delays to Your Codehttps://realpython.com/python-sleep/
classmethod(), staticmethod()https://realpython.com/courses/staticmethod-vs-classmethod-python/
property()https://docs.python.org/3/library/functions.html#property
Primer on Python Decoratorshttps://realpython.com/primer-on-python-decorators/
Python Decorators 101https://realpython.com/courses/python-decorators-101/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#returning-user-defined-objects-the-factory-pattern
user-defined objectshttps://realpython.com/python3-object-oriented-programming/#how-do-you-define-a-class-in-python
factory patternhttps://en.wikipedia.org/wiki/Factory_(object-oriented_programming)
arguments (*args) and keyword arguments (**kwargs)https://realpython.com/python-kwargs-and-args/
https://realpython.com/python-return-statement/#using-return-in-try-finally-blocks
try statementhttps://realpython.com/python-exceptions/#the-try-and-except-block-handling-exceptions
finallyhttps://realpython.com/python-exceptions/#cleaning-up-after-using-finally
https://realpython.com/python-return-statement/#using-return-in-generator-functions
yield statementhttps://realpython.com/introduction-to-python-generators/#understanding-the-python-yield-statement
generator functionhttps://realpython.com/introduction-to-python-generators/
generator iteratorhttps://docs.python.org/3/glossary.html#term-generator-iterator
StopIterationhttps://docs.python.org/3/library/exceptions.html#StopIteration
next()https://docs.python.org/3/library/functions.html#next
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-return-statement/#faqs
custom functionshttps://realpython.com/defining-your-own-python-function/
closure factory functionhttps://realpython.com/inner-functions-what-are-they-good-for/#closures-and-factory-functions
decorator functionshttps://realpython.com/primer-on-python-decorators
https://realpython.com/quizzes/the-python-return-statement/
The Python return Statementhttps://realpython.com/quizzes/the-python-return-statement/
https://realpython.com/feedback/survey/article/python-return-statement/liked/?from=article-footer
https://realpython.com/feedback/survey/article/python-return-statement/disliked/?from=article-footer
Using the Python return Statement Effectivelyhttps://realpython.com/courses/effective-python-return-statement/
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/bweber/
Bryanhttps://realpython.com/team/bweber/
https://realpython.com/team/bweleschuk/
Brendahttps://realpython.com/team/bweleschuk/
https://realpython.com/team/gahjelle/
Geir Arnehttps://realpython.com/team/gahjelle/
https://realpython.com/team/jjablonski/
Joannahttps://realpython.com/team/jjablonski/
https://realpython.com/team/jschmitt/
Jacobhttps://realpython.com/team/jschmitt/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-return-statement
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-return-statement
https://realpython.com/feedback/survey/article/python-return-statement/liked/?from=article-comments
https://realpython.com/feedback/survey/article/python-return-statement/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fpython-return-statement%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20The%20Python%20return%20Statement%3A%20Usage%20and%20Best%20Practices&url=https%3A%2F%2Frealpython.com%2Fpython-return-statement%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20The%20Python%20return%20Statement%3A%20Usage%20and%20Best%20Practices%20https%3A%2F%2Frealpython.com%2Fpython-return-statement%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fpython-return-statement%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/
basicshttps://realpython.com/tutorials/basics/
best-practiceshttps://realpython.com/tutorials/best-practices/
pythonhttps://realpython.com/tutorials/python/
Using the Python return Statement Effectivelyhttps://realpython.com/courses/effective-python-return-statement/
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-return-statement
How to Use Python Lambda Functionshttps://realpython.com/python-lambda/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-return-statement
Python Closures: Common Use Cases and Exampleshttps://realpython.com/python-closure/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-return-statement
Using and Creating Global Variables in Your Python Functionshttps://realpython.com/python-use-global-variable-in-function/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-return-statement
Build Enumerations of Constants With Python's Enumhttps://realpython.com/python-enum/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-return-statement
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-return-statement%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-return-statement%2F
Sign-Inhttps://realpython.com/account/login/?next=/python-return-statement/
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.