코딩

Python Basic 6 (Built-in Function, External Function)

경이가 꿈꾸는 플랫폼 개발 2021. 11. 3. 10:55

내장함수(Built-in Function), 외장함수(External Function)라고도 한다.

 

 

 

내장함수

 

내장함수는 별도의 import 없이 바로 사용 가능한 함수들이다.

내가 자주 쓰는 것들 중 하나는 ord()로, ASCII Code를 리턴해주는 내장함수이다.

아래는 내장함수와 설명을 볼 수 있는 공식 문서이다.

 

Built-in Functions — Python 3.10.0 documentation

Built-in Functions The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order. abs(x) Return the absolute value of a number. The argument may be an integer, a floating poin

docs.python.org

실수로 내장함수를 def 를 통해 잘못 재정의했다면 __builtin__.내장함수명 으로 복원할 수 있다.

sum = 10 + 20
type(sum)

sum = __builtin__.sum
type(sum)

# 30
# builtin_function_or_method

 

 

 

외장함수

 

파이썬 설치시 '기본적'으로 설치된 라이브러리로부터 사용 가능한 함수들이다. 

간단히 말하면 import해서 사용할 수 있는 함수들이다.

외장함수와 설명을 볼 수 있는 공식 문서이다. 계속 공식문서를 첨부하는 이유는, 너무 많아서 다 나열할 수도 없고, version이 달라지면서 추가 혹은 변경이 있을 수 있기 때문에 계속 찾아보는게 좋다.

 

The Python Standard Library — Python 3.10.0 documentation

The Python Standard Library While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python. It also describes some of the opt

docs.python.org

대표적인 모듈에는 time 모듈, datetime 모듈, random 모듈, math모듈, sys모듈이 있다.

일일히 나열할 수도 있지만 사실 찾아보면서 직접 써보는게 실력 향상에 가장 좋다.