써니(>_<) 2022. 7. 18. 08:17

 

A function is a namedset of instructions that performs a specific task.

A function can take one or more parameters (arguments) and returnsa value.

First mechanism for abstraction and decomposition

Advantage of using function : 
  - Facilitates code reuse

  - Helps avoiding repetitive code

  - Hides implementation details

  - Makes testing easier

parameters :

 - You can specify a default valuefor one or more parameters; Parameters with defaults come after parameters without defaults

return : 

-if there is no explicit return, function will return None by default 

-return value can be multiple by using tuple 

 

 

*Abstraction :

Knowing how to use something without knowing how it actually works (how it is implemented)

e.g. making hot coffe using a coffe machine

*Decomposition :

 Break a problem in different, self-contained parts that can be implemented and re-usedseparately