Movatterモバイル変換


[0]ホーム

URL:


The Python return Statement: Usage and Best Practices

Using the Python return Statement Effectively

The Pythonreturn statement is a key component offunctions andmethods. You can use thereturn statement to make your functions send Python objects back to the caller code. These objects are known as the function’sreturn value. You can use them to perform further computation in your programs.

Using thereturn statement effectively is a core skill if you want to code custom functions that arePythonic and robust.

In this course, you’ll learn:

  • How to use thePythonreturn statement in your functions
  • How to returnsingle ormultiple values from your functions
  • Whatbest practices to observe when usingreturn statements
  • How to structure moreadvanced return statements

What’s Included:

  • 22 Lessons
  • Video Subtitles and Full Transcripts
  • 2 Downloadable Resources
  • Accompanying Text-Based Tutorial
  • Interactive Quiz to Check Your Progress
  • Q&A With Python Experts: Ask a Question
  • Certificate of Completion

Downloadable Resources:

Related Learning Paths:

Start Now

Syntax for Writing return Statements in Python

6 Lessons 22m

  1. 1. Using the Python return Statement Effectively (Overview)01:17
  2. 2. Reviewing Python Functions02:46
  3. 3. Using Implicit Returns in Functions03:15
  4. 4. Using Explicit Returns in Functions06:18
  5. 5. Returning vs Printing05:40
  6. 6. Returning Multiple Values03:25

Best Practices for Using return in Python

9 Lessons 39m

  1. 1. Returning None Explicitly02:53
  2. 2. Remembering to Return and Keeping It Readable04:11
  3. 3. Returning Values vs Modifying Global Variables05:08
  4. 4. Using return Statements With Conditionals05:49
  5. 5. Returning Boolean Values04:48
  6. 6. Returning Expressions With Boolean Operators05:28
  7. 7. Using return to Short-Circuit Your Loops04:13
  8. 8. Recognizing and Avoiding Dead Code01:56
  9. 9. Returning Multiple Values With namedtuple04:34

Advanced Uses of return in Python

7 Lessons 29m

  1. 1. Using Functions as Return Values: Closures05:13
  2. 2. Taking and Returning Functions With Decorators06:43
  3. 3. Returning User-Defined Objects With Factory Patterns04:51
  4. 4. Using return With try and finally Blocks03:53
  5. 5. Using return vs yield in Generator Functions03:46
  6. 6. Using the Python return Statement Effectively (Summary)00:52
  7. 7. The Python return Statement (Quiz)04:00
Start Now

AboutHoward Francis

Howard is an avid Pythonista and records video courses for Real Python. He has been teaching beginning programming at the college level for over 20 years in C++, Java, C#, and most recently Python.

» More about Howard

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Related Courses:

Participant Comments

Avatar image for alnah

alnah

This course was outstanding! It was well-structured, clear, and practical. I especially appreciated the sections on closures, decorators/wrappers, and factories. It provides a good introduction to understanding generators as well. The best practices part was very great! Please do that for functions in Python as well!

Avatar image for Shubha

Shubha

Great Course! Learnt a lot. Thank you.

← Browse All Courses


[8]ページ先頭

©2009-2026 Movatter.jp