Popular Posts

Wednesday, August 26, 2020

Python Beginner: Return Statements

 Hello, Python developer!


I hope you have good ideas to utilize functions on your Python programming. 


Today, we will learn the "Return Statements". When you input values into functions through "parameters" and if you want to get calculated values from functions, you can use "Return" command for returning values from function.


Here is definition and example of return command.


Return command example

return function_value # return command should be in the function


I showed full exercise codes and execution result as following.

def cube(num):
num*num*num # There is no return value
print(cube(3))

def cube2(num):
return num * num * num
print(cube2(3))

def cube3(num):
a = num * num * num + 10
b = a * 2
return b

result = cube3(4)
print(result)


Can you see same result? Great! Now you can input and output values in the function.

See you on next post! 




No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...