-
[Function] 함수란🐍 파이썬/파이썬 기본 문법 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
'🐍 파이썬 > 파이썬 기본 문법' 카테고리의 다른 글
what is first class object? (0) 2022.07.18 함수를 함수의 변수로 넘기기 (0) 2022.07.18 working with file (0) 2022.07.17 False in Python (0) 2022.07.17 isinstance(x,y) (0) 2022.07.17