6 Answers
+ 3
#Return is the result of a function. And is given back to the piece of code that called the function. This is an example, newyear() is the function:
def newyear():
return 2018
#You call the function like this:
x = newyear()
print(x) # this will print 2018
+ 3
it just returns a value/values of the function you call
+ 2
Thanks a lot men ;)
+ 2
(i dont actually know python but im gonna try to explain)
for example when you define function
(i guess function defines are like that)
def function_name(parameter)
//codes
for example if you define function that is taking a parameter and returning the increased value,
def increase(x) //x is parameter, increase is function name
x += 2 //increase by two and equal it to x
return x //then return x
if you do this
increase(x) is going to equal to x's increased value
i mean when you are coding
number = input("enter a number: ")
//then print increase function
print(increase(number))
for example if user enters 4 output is going to be 6
+ 2
A function must have a Type and return value
a return just return a value so you need to print it if you need it to show
def max(x, y):<--start function
if x >=y:
return x
else:
return y
<--end function
print(max(4, 7)) <--- max is a function made up ^
so here 4 taken as x and 7 as y
if x >=y: -> 4>=7 False so condtion not taken
return x -> this return will be ignored
else: -> As the first is false this will be true
return y -> it reurn y=7
so max(4,7) have have result 7 and its just printed
Note One return in a true condition return the value and the code not continue to execute
+ 1
omg while i was typing this comment, he understood what is return đđ