ฟังก์ชั่น dir() ในไพทอน เป็น built-in การสร้างฟังก์ชั่น ในไพทอน Python Defining function ฟังก์ชั่น
ซึ่ง ฟังก์ชั่น dir() จะคืนค่าเป็น string ที่เก็บชื่อที่ถูกกำหนดขึ้นใน module ชื่อที่คืนค่าออกมา ประกอบด้วย ชื่อ module , ตัวแปร, ฟังก์ชั่นที่ถูกกำหนดขึ้นภายใน module
ตัวอย่าง
# ตัวอย่าง สอน Python ในเว็บ Mindphp.com
# ทำความรู้จักฟังก์ชั่น dir()
# Import built-in module math
import math
content = dir(math)
print (content)
ผลที่ได้
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']