티스토리 뷰

728x90
반응형

참고 : Python에서 내장함수란 별도로 import 할 필요 없이 사용할 수 있는 함수를 의미합니다.

 

>>> print(dir("hello world"))
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

>>> print(dir({"name":"domdomi"}))
['__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__ior__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__ror__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']

"hello world" 란 문자열에 대한 dir() 함수를 사용하게 되면 문자열이 가지는 내장함수를 모두 출력해줍니다.

또 {"name":"domdomi"} 라는 dict 에 대한 dir() 함수를 사용하면 dict(딕셔너리)가 가질 수 있는 내장함수를 모두 출력해줍니다.

 

위와 같이 각 자료형에 따라 필요한 내장함수들이 어떤 것이 있는지 까먹었다고 생각될 때 위와 같이 출력해서 확인해볼 수 있을 것 같습니다.

 

하지만 일반적으로 가장 편한 방법으로는 구글링이 있을 것 같고, Python 공식 문서를 참고하는 방법도 있을 것 같습니다.

https://docs.python.org/3/library/functions.html

 

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

 

728x90
반응형
댓글