Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- A function which returns several values
- When you're not accustomed with Python, it's easy to forget that a function can return just any type of object, including tuples.
- This a great to create functions which return several values. This is typically the kind of thing that cannot be done in other languages without some code overhead.
- """
- >>> def myfunction(a):
- return (a+1,a*2,a*a)
- >>> print myfunction(3)
- (4, 6, 9)
- """
- You can also use mutiple assignment:
- """
- >>> (a,b,c) = myfunction(3)
- >>> print b
- 6
- >>> print c
- 9
- """
- And of course your functions can return any combination/composition of objects (strings, integer, lists, tuples, dictionnaries, list of tuples, etc.).
- """
Advertisement
Add Comment
Please, Sign In to add comment