Skip to content

Commit 21be0dd

Browse files
committed
Add idomatic way to retrieve multiple return values.
1 parent ddb33c5 commit 21be0dd

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

global_&_return.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,10 @@ Or by more common convention:
119119
age = 30
120120
return name, age
121121
122+
profile_name, profile_age = profile()
123+
print(profile_name)
124+
# Output: Danny
125+
print(profile_age)
126+
# Output: 30
127+
122128
This is a better way to do it along with returning ``lists`` and ``dicts``. Don't use ``global`` keyword unless you know what you are doing. ``global`` might be a better option in a few cases but is not in most of them.

0 commit comments

Comments
 (0)