dir(), .encode()

Grace Goh·2022년 9월 16일
0

Python

목록 보기
5/24
a = "abcd"

print(type(a))
# <class 'str'>

str이 클래스로 만들어져 있다는 의미다.


dir(str)

str 안에 있는 모든 메서드들이 나온다.
함수명으로 유추해볼 수 있는 것들이 많이 있다.

클래스가 어떻게 구성됐고 어떤 함수들이 선언·구현돼 있는지 확인할 수 있다.

print(dir(str))

['__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', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']



encode()

a = "abcd"

print(a.encode())

b'abcd'

바이츠 형태로 변환된 것인데 나중에 다룰 예정이다.
decode()도 있다.

profile
Español, Inglés, Coreano y Python

0개의 댓글