PROGRAMMING

m9/ PYTHON
REMEMBERS




FUNCTIONS

p212 ! A function can return only one value, but if the value is a tuple ... the effect is the same as returning multiple values. If you want to compute the quontient and reminders it is better to ... compute both at the same time.
 
quot = 7//3
rem = 7%3
print(quot, rem)  # 2 1

quot, rem = divmod(7, 3)  # built-in function
print(quot, rem)  # 2 1
p213 ! Functions can take a variable number of arguments. A parameter name that begins with * gathers arguments into a tuple.
 
t = (7, 3)
#divmod(t)  # doesn't work
divmod(*t)  # it works!

Questions    
Files

        A B C D E F
🔔
1/1