tuxmartin

Return multiple values from function

Feb 26th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def test():
  2.     a = 'Hello, '
  3.     b = 'world!'
  4.     c = 123
  5.     return a, b, c
  6.  
  7. x, y, z = test()
  8.  
  9. print x
  10. print y
  11. print z
  12. print x + y
  13.  
  14. ######################## Vystup:
  15.  
  16.  
  17. martin@pc:~$ python
  18. Python 2.7.6 (default, Mar 22 2014, 22:59:56)
  19. [GCC 4.8.2] on linux2
  20. Type "help", "copyright", "credits" or "license" for more information.
  21. >>> def test():
  22. ...     a = 'Hello, '
  23. ...     b = 'world!'
  24. ...     c = 123
  25. ...     return a, b, c
  26. ...
  27. >>> x, y, z = test()
  28. >>>
  29. >>> print x
  30. Hello,
  31. >>> print y
  32. world!
  33. >>> print z
  34. 123
  35. >>> print x + y
  36. Hello, world!
  37. >>>
Advertisement
Add Comment
Please, Sign In to add comment