
FUNCTIONS in Python (Syntax, Create, Call, Arguments, Return, Docstring, Nested, Recursive)
Digital Academy · 2,9 N lượt xem · 25 thg 9, 2020
Mô tả
🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Absolute Beginners, in which you will discover Functions in Python.
▬▬▬▬ 📖 Content ▬▬▬▬
🖥️ In Python, a function is a group of statements that performs a specific task and can be used repeatedly, throughout your program.
Functions in Python help break your program into blocks of code. As your program grows larger and larger, functions make it more organised. It also avoids repetition, makes the code more clear, reusable, and allows you to work collaboratively.
🎯 In this video, you will discover Functions in Python: How to Create and Call a Function in Python, How to Pass arguments to a Function in Python and How to Return a value from a Function in Python? - and more...
Let's play this video, stick around and watch until the end! 👍🏻
Digital Academy™ 🎓
Create a Function in Python
---------------------------------------------
To define a function in Python, use the keyword def, followed by your function name with parenthesis, optional arguments, and one colon.
def my_function(arg1, arg2):
statement 1
statement 2
return result
Call a Function in Python
-----------------------------------------
The def statement only creates a function, but does not call it afterwards. You must call (run) the function explicitly by adding parentheses after the function’s name. Therefore, once you have defined your function, you can call it from another function and anywhere in your program.