0

Python

Please I don't understand topics under Function and Module in python

25th Sep 2019, 12:05 PM
Ayooluwa Adeleye
Ayooluwa Adeleye - avatar
6 Answers
+ 1
Function is a statement that takes arguments, and returns a value depending on the arguments. In programming you can use functions to make calculations and you can also use functions to run certain pieces of code. Here are the main parts: ~Function definition ~Function call ~Function return Function definition: def func_name(arg1, arg2, ... argN): code In Python function definition defines 3 things: ~function name: name to be used when calling the function, function names follow variable naming rules. ~parameters: comma separated variables between parentheses are parameters, which define how arguments should be passed. ~code: basic python code, that will be run when function is called.
25th Sep 2019, 3:10 PM
Seb TheS
Seb TheS - avatar
+ 1
Function call: func_name(value1, value2, ... valueN) When function name is followed by (), the function will be called. It can take arguments, (basic values, such as integers, strings, lists and booleans), how they are passed is defined by the function parameters. When function is called, the arguments get copied to the function parameter and the parameters can be used as variables in the function code part.
25th Sep 2019, 3:20 PM
Seb TheS
Seb TheS - avatar
+ 1
Function call ends to a return value. Functions can return any values using return statement in function code part. The returned value can be any basic value, when function is called and any return statement is used, the return value will be returned to where the function was called. Some examples: def func(): return "Batman" return "Ironman" print(func()) #Output: Batman def func(): print("Hello world!") return 80 print("100th time!") print(func()) #Output: Hello world! 80 def get_area(width, height): return width*height print(get_area(4, 8)) #Output: 32 If there is no return statement or no return statement is reached during the function call, then None is returned by default. def useless_function(): pass print(useless_function()) #Output: None (pass does not do anything, it's just a keyword for empty codeblocks to avoid errors.)
25th Sep 2019, 3:26 PM
Seb TheS
Seb TheS - avatar
0
Hi. What exactly you don't understand?
25th Sep 2019, 12:14 PM
Dmytro Novak
Dmytro Novak - avatar
0
Using Functions
25th Sep 2019, 12:16 PM
Ayooluwa Adeleye
Ayooluwa Adeleye - avatar
0
Here's the that I Googled ant it explains the use of functions in Python. https://www.learnpython.org/en/Functions
25th Sep 2019, 12:20 PM
Dmytro Novak
Dmytro Novak - avatar