Chapter 6 - Function
Chapter 6 - Function
Chapter 6
Function
Function
• Python built-in functions: int(), input(), print(), str(), etc
• We can define a function in Python
• Tujuan function:
• Make it easy to develop programs
• Save the number of lines in the source code
• Make it easier for teamwork management to work on projects
• The program becomes more structured/flow, and the program is easy to
understand
• Easier to make documentation
• Reusability -> function can be reused in other programs
1
31/10/2022
2
31/10/2022
Dynamic Argument
3
31/10/2022
Non-void Function
• Void Function: a function that only executes the instructions as
defined, no value is returned from the function
• Non-Void Function: a function that executes the instruction as
defined, and there is a value returned from that function. This value
will be used for other calculations.
• Characteristics of non-void function:
• There is a return command inside the function
• The function call is inside an expression
4
31/10/2022
myscript1.py
hello.py or…
“hello” library
myscript2.py
Here is how:
or
import modules.hello
5
31/10/2022
Example 2