Dec-12-2017, 03:20 AM
Consider this:
def pow(number, power): # calculating an exponent result = 1 for _ in range(power): result = result * number # the function always returns a value. If you do not specify what will be that value it will be None. # So, you may print it or just generate it some way. But outside of the function, this variable will be untouchable. # If you put raw materials in some kind of super duper sophisticated machine it may produce a laptop. # But if there is no functionality to get the production out good for you - no laptop. :D # So here it is - the return statement return result powers = [] for num in range(1,5): power = pow(num, 3) # here the result of the pow() is returned and assgned to a variable. powers.append(power) print(powers)
Output:[1, 8, 27, 64]