Python(Eng. ver)
12. User-Defined Function
곽정우
2024. 3. 15. 16:07
1. User-Defined Functions
It is functions that you create yourself to perform specific tasks. Python has many built-in functions, but sometimes you need to create a function that behaves exactly as you need it to. This is where user-defined functions come in.
1-1. Functions with no parameters and no return value
- The simplest form of a function
- It performs a specific task and the result is printed on the screen or stored in another variable.
1-2. Functions with parameters and no return value
- These functions receive the data needed to run the function as parameters.
1-3. Functions with return values
- These functions return the result of the function execution as a value.
1-4. Parameters with default values
- Setting default values for parameters allows user to omit those parameters when calling the function.
1-5. Variable arguments
- 함수를 호출할 때 *를 사용하면 시퀀스(리스트, 튜플 등)의 요소를 개별적인 위치 인자로 풀어서 전달할 수 있습니다.
1-6. Keyword arguments
- 인자 순서에 관계없이 키워드와 함께 값을 전달하는 방식입니다.
1-7. Multiple return values
- 함수에서 여러 개의 값을 동시에 반환할 수 있습니다.