Python / dir() / 객체의 메소드 등을 반환하는 함수

예제 1

a = "Hello"
print( dir( a ) )
['__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']

예제 2

a = [ "1", "2" ]
print( dir( a ) )
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

예제 3

import math
print( dir( math ) )
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp']

Related Posts

Python / str() / 자료형을 문자열로 변환하는 함수

Python / str() / 자료형을 문자열로 변환하는 함수

str()은 데이터 타입을 문자열로 변환하는 함수이다. >>> a = 1 >>> type( a ) <class 'int'> >>> print( a ) 1 >>> b = str( a ) >>> type( b ) <class 'str'> >>> print( b ) 1 >>> a = 1.23 >>> type( a ) <class 'float'> >>> print( a ) 1.23 >>> b = str( a ) >>> type( b ) <class 'str'> >>> print( b ) 1.23 Python ...

Python / 문법 / 주석

Python / 문법 / 주석

주석에는 한 줄 주석과 여러 줄 주석이 있습니다. 한 줄 주석은 #을 사용합니다. # 뒤의 문자열이 주석이 됩니다. # 한 줄 주석 print( "Hello" ) # Hello 출력 여러 줄 주석은 작은 따옴표 세 개('''), 또는 큰 따옴표 세 개(""")를 사용합니다. 혼용할 수는 없습니다. ''' print( "Hello" ) print( "World" ) ''' print( "Hello" ) print( "World" ) """ print( "Hello" ) print( "World" ...

Python / input() / 사용자가 입력한 값을 변수에 저장하는 함수

Python / input() / 사용자가 입력한 값을 변수에 저장하는 함수

input() 함수로 사용자가 어떤 값을 입력하게 하고, 그 값을 변수에 저장할 수 있습니다. 문법 예를 들어 다음을 입력하고 엔터를 누르면 사용자가 값을 입력하기를 기다립니다. >>> x = input() 값을 입력하고 엔터를 누르면 그 값이 변수 x에 저장됩니다. >>> x = input() hello >>> x 'hello' 입력할 값에 대한 안내를 출력하고 싶다면 다음과 같이 합니다. >>> x = input('some text') 작은 따옴표 ...

Python / len() / 문자열의 길이 반환하는 함수

Python / len() / 문자열의 길이 반환하는 함수

len()은 문자열의 길이 반환하는 함수이다. 간단한 예는 다음과 같다. len( "abc" ) # 3 반환 정수나 실수 등은 문자열이 아니므로 에러가 난다. 문자열로 변환한 후 센다. len( str( 1234 ) ) # 4 반환 한글도 1로, 공백도 1로 센다. len( "한글과 공백" ) # 6 반환 리스트나 튜플 등에서는 그 안에 속한 값의 ...

Python / dir() / 객체의 메소드 등을 반환하는 함수

Python / dir() / 객체의 메소드 등을 반환하는 함수

예제 1 a = "Hello" print( dir( a ) ) ['__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', ...

Python / int() / 자료형을 정수로 변환하는 함수

Python / int() / 자료형을 정수로 변환하는 함수

int()는 데이터 타입을 정수로 변환하는 함수이다. 실수를 정수로 변환하는 경우 소숫점 아래 수를 없앤다. 숫자로 이루어진 문자열을 정수로 변환할 수 있다. >>> print( "int( 1.2 ) : ", int( 1.2 ) ) int( 1.2 ) : 1 >>> print( "int( 1.7 ) : ", int( 1.7 ) ) int( 1.7 ) : 1 >>> print( ...

Python / 모듈(module) 사용하기

Python / 모듈(module) 사용하기

모듈 가져오고 사용하기 import로 모듈을 가져옵니다. 예를 들어 math 모듈을 가져오고 싶다면 >>> import math 모듈에 포함된 함수 등 목록을 보고 싶다면 dir() 함수를 이용합니다. >>> dir(math) ['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', ...

Python / float() / 자료형을 실수로 변환하는 함수

Python / float() / 자료형을 실수로 변환하는 함수

float()는 데이터 타입을 실수로 변경하는 함수이다. 정수를 실수로 변환한다. 정수일 때는 소숫점 아래가 없지만, 실수일 때는 있다. >>> a = 1 >>> type( a ) <class 'int'> >>> print( a ) 1 >>> b = float( a ) >>> type( b ) <class 'float'> >>> print( b ) 1.0 숫자로 이루어진 문자열을 실수로 변경한다. >>> a = '1' >>> type( a ) <class 'str'> >>> print( ...

Python / 자료형 / 사전(dict)

Python / 자료형 / 사전(dict)

사전(dict) 사전은 집합의 일종으로, 키와 값이 하나의 데이터를 만듭니다. 순서가 없고 중복된 데이터를 갖지 않아서, 중복 데이터를 만드는 +, *를 사용할 수 없지만, 키를 이용하여 인덱스기호()를 사용할 수 있습니다. 사전 만들기 사전은 집합과 마찬가지로 중괄호로 만듭니다. 키를 앞에, 값을 뒤에 쓰고, 구분은 콜론(:)으로 합니다. 데이터의 구분은 쉼표(,)로 합니다. >>> jb = {1:"one", 2:"two", 3:"three"} >>> jb {1: 'one', ...

Python / print() / 출력하는 함수

Python / print() / 출력하는 함수

Python의 print() 함수 사용법을 정리합니다. 큰 따옴표를 이용하여 Hello를 출력합니다. print("Hello") Hello 작은 따옴표를 이용하여 Hello를 출력합니다. print('Hello') Hello 작은 따옴표를 출력하려면 큰 따옴표로 감쌉니다. print("'Hello'") 'Hello' 큰 따옴표를 출력하려면 작은 따옴표로 감쌉니다. print('"Hello"') "Hello" 쉼표로 연결할 수 있습니다. 공백이 생깁니다. print("Hello","JB") Hello JB print() 함수를 연달아 사용하면 다른 줄에 출력됩니다. print("Hello") print("JB") Hello JB 줄바꿈 없이 출력하려면 end를 사용합니다. print("Hello",end=" ") print("JB") Hello JB sep를 이용하여 출력 값 사이에 특정 문자를 넣을 수 있습니다. print("A","B","C","D",sep=" ...