Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

파이썬의 dir() 함수

<시간/>

dir() 내장 함수는 모듈에 의해 정의된 이름을 포함하는 정렬된 문자열 목록을 반환합니다.

목록에는 모듈에 정의된 모든 모듈, 변수 및 함수의 이름이 포함됩니다. 다음은 간단한 예입니다 -

#!/usr/bin/python
# Import built-in module math
import math
content = dir(math)
print content

출력

위의 코드가 실행되면 다음과 같은 결과가 생성됩니다 -

['__doc__', '__file__', '__name__', 'acos', 'asin', 'atan',
'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp',
'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log',
'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh',
'sqrt', 'tan', 'tanh']

여기서 특수 문자열 변수 __name__은 모듈의 이름이고 __file__은 모듈이 로드된 파일 이름입니다.