Python-Ref > Basic usage > Functions > Returning more values from a function
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Returning more values from a function

Sometimes it is useful to return more than one value as a result of a function. In this case it is possible to return a list, but more usually tuples are used. Tuple unpacking can be then conveniently used to assign the return values to variables.
Expand/Shrink
Zdroj: (func7-1.py)
  1   def integer_division( m, n):
  2       """this function returns both the result of integer division
  3       of m and n and the remainder after division"""
  4       return m // n, m % n
  5   
  6   
  7   print integer_division( 13, 4)
  8   
  9   x, y = integer_division( 21, 8)   # tuple unpacking
 10   print x
 11   print y
stdout:
(3, 1)
2
5
Doba běhu: 20.8 ms