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']
같은 카테고리의 다른 글
Python / 객체(Object)와 변수(Variable)

Python / 객체(Object)와 변수(Variable)

객체(Object), 변수(Variable), 변수명(Variable Name) 메모리에 저장된 자료를 객체(object)라고 한다. 객체를 저장한 공간을 변수(Variable), 변수의 이름을 변수명(Variable Name)이라고 한다. 변수에 객체를 넣을 때 등호 '='을 이용한다. 등호 왼쪽에는 변수명, 등호 오른쪽에는 객체를 적는다. 예를 들어 다음은 객체 100을 x라는 이름의 변수에 저장하겠다는 뜻이다. x = 100 변수명은 다음의 규칙을 지켜야 한다. 규칙에 맞지 않으면 에러가 난다. 키워드를 ...

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 / 사용자 정의 함수 만들고 호출하기

Python / 사용자 정의 함수 만들고 호출하기

함수를 정의하고 호출하는 방법을 알아봅니다. 함수 만들기 def function_name( parameter ) : # code function_name : 함수 이름입니다. 변수명을 만드는 규칙과 같은 규칙으로 만듭니다. parameter : 인수입니다. 인수가 여러 개인 경우 쉼표(,)로 구분합니다. 함수 호출하기 function_name( parameter ) 예제 Hello를 출력하는 함수를 정의합니다. def jb_say_hello() : print('Hello') 함수를 호출하면 Hello가 출력됩니다. >>> jb_say_hello() Hello 함수를 정의하는 위치 함수는 ...

Python / 자료형 / 집합(set)

Python / 자료형 / 집합(set)

집합(set) 집합은 여러 개의 자료를 하나의 변수로 관리할 때 사용하는 자료형 중의 하나입니다. 집합 자료형은 수학의 집합과 같은 성질을 가집니다. 즉, 집합은 중복된 데이터를 가질 수 없고, 순서가 없습니다. 따라서 순서와 관련된 인덱스기호()를 사용할 수 없고, 중복 데이터를 만드는 +, *를 사용할 수 없습니다. 하지만, in, not in, len()은 사용할 수 있습니다. 집합 만들기 집합은 중괄호로 만듭니다. >>> ...

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 / 자료형 / 숫자

Python / 자료형 / 숫자

숫자 자료 만들기 숫자 자료는 따옴표 없이 숫자만 넣어서 만든다. 소숫점이 없으면 정수형 자료, 소숫점이 있으면 실수형 자료가 만들어진다. 정수형 자료의 타입은 int, >>> a = 100 >>> print( type( a ) ) <class 'int'> 실수형 자료의 타입은 float이다. >>> a = 100.1 >>> print( type( a ) ) <class 'float'> 숫자 연산자 사칙 연산 +는 더하고, -는 빼고, *는 곱하고, /는 ...

Python / 자료형 / 문자열(string)

Python / 자료형 / 문자열(string)

문자열 자료 만들기 문자열(string) 자료는 큰 따옴표 또는 작은 따옴표로 감싸서 만든다. >>> str_a = "Hello" >>> print( str_a ) Hello >>> str_a = 'Hello' >>> print( str_a ) Hello 숫자여도 따옴표로 감싸면 문자열이 된다. >>> str_a = "123" >>> type( str_a ) <class 'str'> 문자열에 따옴표 포함하기 문자열에 작은 따옴표를 포함하고 싶다면 큰 따옴표로 감싸고... >>> str_a = "'Hello'" >>> print( str_a ) 'Hello' 큰 따옴표를 ...

Python / range() / 연속된 수 또는 일정 간격의 연속된 수를 만드는 함수

Python / range() / 연속된 수 또는 일정 간격의 연속된 수를 만드는 함수

range() range() 함수는 연속된 수 또는 일정 간격의 연속된 수를 만드는 함수입니다. for 반복문에 자주 사용됩니다. 문법 range(stop) 0부터 시작하여 stop보다 하나 작은 수까지 만듭니다. range(start, stop) start부터 시작하여 stop보다 하나 작은 수까지 만듭니다. range(start, stop, step) start부터 시작하여 stop보다 하나 작은 수까지 step 간격으로 수를 만듭니다. 예제 1 0부터 3까지의 수를 만듭니다. >>> list(range(4)) 1부터 10까지의 수를 만듭니다. >>> ...

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 / Visual Studio Code 개발 환경 만들기

Python / Visual Studio Code 개발 환경 만들기

파이썬 개발을 위한 도구는 여러 가지가 있습니다. Visual Studio Code도 그 중 하나입니다. VS Code에 Python 확장 기능을 설치하고, Hello World를 출력해보겠습니다. 확장 기능 설치 Visual Studio Code를 설치하고 실행합니다. 사각형 모양의 확장 기능 아이콘을 클릭합니다. python으로 검색한 후, 다운로드 수가 가장 많은 Microsoft가 만든 Python을 설치합니다. Reload Required를 클릭합니다.(VS Code 버전에 따라 나오지 않을 ...