ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด/Python

[Python] ๋‚ด์žฅ ํ•จ์ˆ˜

NaNaRin๐Ÿ™ƒ 2021. 2. 10. 23:00

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

 

Built-in Functions — Python 3.9.1 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


1. ์ •์ˆ˜์˜ ์ง„์ˆ˜ ๋ณ€ํ™˜

2. ์•„์Šคํ‚ค์ฝ”๋“œ <ใ…ก> ์ˆซ์ž

3. ์ž๋ฃŒํ˜• ๋ณ€ํ™˜, ๊ฐ์ฒด ํƒ€์ž…๊ณผ ๊ธธ์ด

4. iterable ์ฒ˜๋ฆฌ

5. ์ˆ˜ํ•™

6. ์ž…์ถœ๋ ฅ

7. ๊ธฐํƒ€


ํŒŒ์ด์ฌ ๋‚ด์žฅ ํ•จ์ˆ˜๋Š” ์™ธ๋ถ€ ๋ชจ๋“ˆ๊ณผ ๋‹ฌ๋ฆฌ import๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š์•„ ์•„๋ฌด๋Ÿฐ ์„ค์ • ์—†์ด ๋ฐ”๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค

+ iterable : ๋ฐ˜๋ณต ๊ฐ€๋Šฅํ•œ ์ž๋ฃŒํ˜•, ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์ž๋ฃŒํ˜•. ๋ฌธ์ž์—ด, ๋ฆฌ์ŠคํŠธ, ํŠœํ”Œ, ๋”•์…”๋„ˆ๋ฆฌ, ์ง‘ํ•ฉ ๋“ฑ


1. ์ •์ˆ˜์˜ ์ง„์ˆ˜ ๋ณ€ํ™˜

 

- bin(x)

 : ์ •์ˆ˜๋ฅผ 0b ์ ‘๋‘์‚ฌ๊ฐ€ ๋ถ™์€ 2์ง„์ˆ˜ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜

a = bin(10)
b = bin(20)
print(a, b)			
# 0b1010 0b10100

 

- oct(x)

 : ์ •์ˆ˜๋ฅผ 0o ์ ‘๋‘์‚ฌ๊ฐ€ ๋ถ™์€ 8์ง„์ˆ˜ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜

a = oct(10)
b = oct(20)
print(a, b)
# 0o12 0o24

 

- hex(x)

 : ์ •์ˆ˜๋ฅผ 0x ์ ‘๋‘์‚ฌ๊ฐ€ ๋ถ™์€ ์†Œ๋ฌธ์ž 16์ง„์ˆ˜ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜

a = hex(10)
b = hex(20)
print(a, b)
# 0xa 0x14

2. ์•„์Šคํ‚ค์ฝ”๋“œ <ใ…ก> ์ˆซ์ž

 

- chr(x)

 : ์ˆซ์ž x๋ฅผ ์•„์Šคํ‚ค์ฝ”๋“œ๋กœ ๊ฐ€์ง€๋Š” ๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜ ( ord(x)์™€ ๋ฐ˜๋Œ€ )

sa = chr(97)
ba = chr(65)
print(sa, ba)		
# a A

 

- ord(x)

 : ์•„์Šคํ‚ค์ฝ”๋“œ ๋ฌธ์ž x๋ฅผ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜ ( chr(x)์™€ ๋ฐ˜๋Œ€ )

sa = ord('a')
ba = ord('A')
print(sa, ba)
# 97 65

3. ์ž๋ฃŒํ˜•, ๊ฐ์ฒด ํƒ€์ž…๊ณผ ๊ธธ์ด

 

- bool(x)

 : x๊ฐ€ ๊ฑฐ์ง“์ด๊ฑฐ๋‚˜ ์ƒ๋žต๋˜๋ฉด False, ์ฐธ์ด๋ฉด True ๋ฐ˜ํ™˜

a = bool()
b = bool(1)
c = bool(0)
d = bool(-1)
print(a, b, c, d)	
# False True False True

 

- dict(**kwarg) / dict(mapping, **kwarg) / dict(iterable, **kwarg)

 : ์ƒˆ dict๋ฅผ ๋งŒ๋“ฌ

a = dict()
b = {'a': 1}
print(type(a))      # <class 'dict'>
print(type(b))      # <class 'dict'>

 

- frozenset([iterable])

 : ์ƒˆ frozenset์„ ๋งŒ๋“ค๊ฑฐ๋‚˜ ์ธ์ˆ˜๋ฅผ frozensetํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜

a = frozenset()
b = {1, 2, 3}
print(type(a))      # <class 'frozenset'>
print(type(b))      # <class 'set'>

 

- int([x]) / int(x, base=10)

 : ์ˆซ์ž๋‚˜ ๋ฌธ์ž์—ด x๋ฅผ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜. ์ธ์ž๊ฐ€ ์ฃผ์–ด์ง€์ง€ ์•Š์œผ๋ฉด 0 ๋ฐ˜ํ™˜. base(์ง„๋ฒ•) ์‚ฌ์šฉ์‹œ base์ง„๋ฒ•์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜

a = 123
print(int(a))               # 123
b = '123'
print(int(b))               # 123
c = 'a'
print(int(c, base=16))      # 10

 

- list([iterable])

 : ์ƒˆ list๋ฅผ ๋งŒ๋“ค๊ฑฐ๋‚˜ ์ธ์ˆ˜๋ฅผ listํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜

a = list()
print(type(a))      # <class 'list'>
b = (1, 2, 3)
print(type(b))      # <class 'tuple'>
c = list(b)
print(type(c))      # <class 'list'>

 

- set([iterable])

 : ์ƒˆ set์„ ๋งŒ๋“ค๊ฑฐ๋‚˜ ์ธ์ˆ˜๋ฅผ setํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜

a = set()
print(type(a))      # <class 'set'>
b = (1, 2, 3, 2)
print(b)            # (1, 2, 3, 2)
print(type(b))      # <class 'tuple'>
c = set(b)
print(c)            # {1, 2, 3}
print(type(c))      # <class 'set'>

 

- str(object='') / str(object=b'', encoding='utf-8', errors='strict')

 : object์„ strํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜

a = 123
print(type(a))          # <class 'int'>
b = str(a)
print(type(b))          # <class 'str'>
c = [1, 2, 3]
print(type(c))          # <class 'int'>
d = str(c)
print(d, type(d))       # [1, 2, 3] <class 'str'>
print(d[2:7])           # , 2, 

 

- tuple([iterable])

 : ์ƒˆ tuple์„ ๋งŒ๋“ค๊ฑฐ๋‚˜ ์ธ์ˆ˜๋ฅผ tupleํ˜•์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜

a = tuple()
print(type(a))      # <class 'tuple'>
b = [1, 2, 3]
print(type(b))      # <class 'list'>
c = tuple(b)
print(type(c))      # <class 'tuple'>

 

- type(object)

 : ๊ฐ์ฒด์˜ ํƒ€์ž… ๋ฐ˜ํ™˜

a = [1, 2, 3, 4]
print(type(a))      # <class 'list'>
b = (1, 2, 3, 4)
print(type(b))      # <class 'tuple'>
c = {1: 2, 3: 4}
print(type(c))      # <class 'dict'>
d = {1, 2, 3, 4}
print(type(d))      # <class 'set'>

 

- len(s)

 : ๊ฐ์ฒด์˜ ๊ธธ์ด(์š”์†Œ ์ˆ˜)๋ฅผ ๋ฐ˜ํ™˜

a = [1, 2, 3, 4]
print(len(a))
# 4

4. iterable ์ฒ˜๋ฆฌ

 

- all(iterable)

 : iterable์˜ ๋ชจ๋“  ์š”์†Œ๊ฐ€ ์ฐธ์ด๋ฉด True ๋ฐ˜ํ™˜ ( ๋น„์–ด์žˆ์œผ๋ฉด True ๋ฐ˜ํ™˜ )

a = [1, 3, 7, 0]
b = [5, 'a', 10, 'abc']
c = [0, 0, 0, 0]
d = []
print(all(a), all(b), all(c), all(d))	
# False True False True

 

- any(iterable)

 : iterable์˜ ์š”์†Œ ์ค‘ ์–ด๋Š ํ•˜๋‚˜๋ผ๋„ ์ฐธ์ด๋ฉด True ๋ฐ˜ํ™˜ ( ๋น„์–ด์žˆ์œผ๋ฉด False )

a = [1, 3, 7, 0]
b = [5, 'a', 10, 'abc']
c = [0, 0, 0, 0]
d = []
print(any(a), any(b), any(c), any(d))	
# True True False False

 

- enumerate(iterable[, start=0])

: ์นด์šดํŠธ( ๋””ํดํŠธ๊ฐ’ 0์ธ start ๋ถ€ํ„ฐ )์™€ iterable์„ ํฌํ•จํ•˜๋Š” ํŠœํ”Œ์„ ๋ฐ˜ํ™˜. ์ดํ„ฐ๋ ˆ์ดํ„ฐ๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ๊ฐ ์•„์ดํ…œ์˜ ์ธ๋ฑ์Šค๋ฅผ ์–ป์–ด์˜จ๋‹ค

seasons = ['Spring', 'Summer', 'Fall', 'Winter']

a = list(enumerate(seasons))
print(a)			
# [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]

b = list(enumerate(seasons, start=4))
print(b)			
# [(4, 'Spring'), (5, 'Summer'), (6, 'Fall'), (7, 'Winter')]

 

- filter(function, iterable)

 : function์œผ๋กœ ์ „๋‹ฌ๋œ ํ•จ์ˆ˜๊ฐ€ ์ฐธ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” iterable์˜ ์š”์†Œ๋“ค๋งŒ ๋ฐ˜ํ™˜

a = [True, False, True, True, False]
b = list(filter(bool, a))
print(a)
# [True, False, True, True, False]
print(b)
# [True, True, True]

 

- map(function, iterable, …)

 : iterable์˜ ๋ชจ๋“  ํ•ญ๋ชฉ์— function์„ ์ ์šฉํ•œ ํ›„ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜. ์ถ”๊ฐ€ iterable ์ธ์ž๊ฐ€ ์ „๋‹ฌ๋˜๋ฉด ๊ทธ ์ˆ˜๋งŒํผ funtion์ด ์ธ์ž๋ฅผ ๊ฐ€์ ธ์•ผ ํ•˜๋ฉฐ, ๊ฐ€์žฅ ์งง์€ iterable์ด ๋ชจ๋‘ ์†Œ๋ชจ๋˜๋ฉด ์ค‘๋‹จ

def tk(t, k):
    return t * k

a = [1, 2, 3, 4]
b = [5, 6, 7, 8, 9]
c = list(map(tk, a, b))
print(c)
# [5, 12, 21, 32]

 

- reversed(seq)

 : ์—ญ ์ดํ„ฐ๋ ˆ์ดํ„ฐ ๋ฐ˜ํ™˜

a = [1, 2, 3]
b = list(reversed(a))
print(b)
# [3, 2, 1]

 

- sorted(iterable, *, key=None, reverse=False)

 : iterable์˜ ํ•ญ๋ชฉ๋“ค์„ ์•ˆ์ •์ (stable)์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ๋ฐ˜ํ™˜. key๋Š” ํ•˜๋‚˜์˜ ์ธ์ž๋ฅผ ๋ฐ›๋Š” ํ•จ์ˆ˜ ์ง€์ •. reverse๋Š” ๋…ผ๋ฆฌ๊ฐ’์œผ๋กœ True๋กœ ์„ค์ •ํ•˜๋ฉด ๊ฐ ๋น„๊ต๊ฐ€ ๋’ค์ง‘ํ˜€ ์ •๋ ฌ

def tt(t):
    return t[1]

a = [[4, 7], [1, 3], [2, 8], [5, 1]]
b1 = sorted(a, key=tt, reverse=False)
print(b1)           
# [[5, 1], [1, 3], [4, 7], [2, 8]] ๋‘๋ฒˆ์งธ ์š”์†Œ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
b2 = sorted(a, key=lambda t: t[1], reverse=True)
print(b2)           
# [[2, 8], [4, 7], [1, 3], [5, 1]] ๋‘๋ฒˆ์งธ ์š”์†Œ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ

c = [[1, 4, 2], [7, 1, 0], [6, 5, 0], [3, 2, 0]]
d1 = sorted(c, key=lambda t: (t[2], t[1]))
print(d1)           
# [[7, 1, 0], [3, 2, 0], [6, 5, 0], [1, 4, 2]] ์„ธ๋ฒˆ์งธ ์š”์†Œ, ๋‘๋ฒˆ์งธ ์š”์†Œ ์ˆœ์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ

 

- zip(*iterables)

 : ๊ฐ iterable์˜ ์š”์†Œ๋“ค์„ ๋ชจ์œผ๋Š” ์ดํ„ฐ๋ ˆ์ดํ„ฐ ๋ฐ˜ํ™˜. ๊ฐ€์žฅ ์งง์€ iterable์ด ๋ชจ๋‘ ์†Œ๋ชจ๋˜๋ฉด ์ค‘๋‹จ

a = [1, 3, 4, 23, 6]
b = ['a', 'd', 'we', 'qs']
c = list(zip(a, b))
print(c)
# [(1, 'a'), (3, 'd'), (4, 'we'), (23, 'qs')]

5. ์ˆ˜ํ•™

 

- abs(x)

 : ์ •์ˆ˜, ์‹ค์ˆ˜์˜ ์ ˆ๋Œ“๊ฐ’์„ ๋ฐ˜ํ™˜

a = -10
b = 0
c = 34
d = -1.2
e = 3.56
print(abs(a), abs(b), abs(c), abs(d), abs(e))
# 10 0 34 1.2 3.56

 

- divmod(a, b)

 : ๋‘๊ฐœ์˜ ์ˆซ์ž๋ฅผ ์ธ์ž๋กœ ์ทจํ•ด ๋ชซ๊ณผ ๋‚˜๋จธ์ง€๋กœ ๊ตฌ์„ฑ๋œ ํŠœํ”Œ์„ ๋ฐ˜ํ™˜

a = divmod(18, 4)
print(a)			
# (4, 2)

 

- max(iterable, x[, key=, defalut=])  / max(arg1, arg2, *args[, key])

 : iterbale ์ค‘ ๊ฐ€์žฅ ํฐ ์š”์†Œ๋‚˜ ๋‘ ๊ฐœ ์ด์ƒ์˜ ์ธ์ž ์ค‘ ๊ฐ€์žฅ ํฐ ์š”์†Œ๋ฅผ ๋ฐ˜ํ™˜. ์—ฌ๋Ÿฌ ํ•ญ๋ชฉ์ด ์ตœ๋Œ“๊ฐ’์ด๋ฉด ์ฒ˜์Œ ๋งŒ๋‚œ ์š”์†Œ๋ฅผ ๋ฐ˜ํ™˜. iterable์ด ๋น„์–ด์žˆ์œผ๋ฉด default ๋ฐ˜ํ™˜ํ•˜๊ณ  default๊ฐ€ ์ธ์ž๋กœ ์ฃผ์–ด์ง€์ง€ ์•Š์œผ๋ฉด ValueError ๋ฐœ์ƒ. key์—๋Š” ํ•จ์ˆ˜ ํ˜น์€ lambda๋ฅผ ์ „๋‹ฌํ•˜๋ฉฐ key๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ฐ’์„ ํƒ์ƒ‰

a = [-7, 2, 3, 0]
b = []
print(max(b, default=1))
# 1
print(max(a))
# 3
print(max(a, key=abs))
# -7
print(max(-7, 2, 3, 0, key=abs))
# -7
print(max(a, key=lambda x: x % 4))
# 3

 

- min(iterable, x[, key=, defalut=])  / min(arg1, arg2, *args[, key])

 : iterbale ์ค‘ ๊ฐ€์žฅ ์ž‘์€ ์š”์†Œ๋‚˜ ๋‘ ๊ฐœ ์ด์ƒ์˜ ์ธ์ž ์ค‘ ๊ฐ€์žฅ ์ž‘์€ ์š”์†Œ๋ฅผ ๋ฐ˜ํ™˜. ์—ฌ๋Ÿฌ ํ•ญ๋ชฉ์ด ์ตœ์†Ÿ๊ฐ’์ด๋ฉด ์ฒ˜์Œ ๋งŒ๋‚œ ์š”์†Œ๋ฅผ ๋ฐ˜ํ™˜. iterable์ด ๋น„์–ด์žˆ์œผ๋ฉด default ๋ฐ˜ํ™˜ํ•˜๊ณ  default๊ฐ€ ์ธ์ž๋กœ ์ฃผ์–ด์ง€์ง€ ์•Š์œผ๋ฉด ValueError ๋ฐœ์ƒ. key์—๋Š” ํ•จ์ˆ˜ ํ˜น์€ lambda๋ฅผ ์ „๋‹ฌํ•˜๋ฉฐ key๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ฐ’์„ ํƒ์ƒ‰

a = [-7, 2, 3, 0]
b = []
print(min(b, default=1))
# 1
print(min(a))
# -7
print(min(a, key=abs))
# 0
print(min(-7, 2, 3, 0, key=abs))
# 0
print(min(a, key=lambda x: x % 4))
# 0

 

- pow(base, exp[, mod=])

 : base์˜ exp ๊ฑฐ๋“ญ์ œ๊ณฑ ๊ฐ’ ๋ฐ˜ํ™˜ ( == base**exp ) mod ์ธ์ž๊ฐ€ ์ „๋‹ฌ๋˜๋ฉด base ** exp % mod ๊ฐ’ ๋ฐ˜ํ™˜

print(pow(2, 3))
# 8
print(pow(2, 3, mod=3))
# 2

 

- round(number[, ndigits=])

 : number๋ฅผ ์†Œ์ˆ˜์  ๋‹ค์Œ์— ndigits ์ •๋ฐ€๋„(์ž๋ฆฌ์ˆ˜)๋กœ ๋ฐ˜์˜ฌ๋ฆผํ•œ ๊ฐ’ ๋ฐ˜ํ™˜. ndigits๊ฐ€ ์ธ์ˆ˜๋กœ ์ฃผ์–ด์ง€์ง€ ์•Š์œผ๋ฉด ๋ฐ˜์˜ฌ๋ฆผํ•œ ์ •์ˆ˜ ๋ฐ˜ํ™˜. ๊ณ„์‚ฐํ•  ์ˆ˜๊ฐ€ ์˜ฌ๋ฆผ, ๋‚ด๋ฆผํ–ˆ์„๋•Œ ๋™์ผํ•˜๊ฒŒ ์ฐจ์ด๋‚˜๋Š” ๊ฒฝ์šฐ ์ง์ˆ˜ ๊ฐ’์œผ๋กœ ๋ฐ˜์˜ฌ๋ฆผ

print(round(0.5))
# 2
print(round(1.5))
# 0
print(round(1.2372, ndigits=2))
# 1.24

 

- sum(iterable[, start=0])

 : start ๋ฐ iterable์˜ ์š”์†Œ๋ฅผ ์™ผ์ชฝ๋ถ€ํ„ฐ ์˜ค๋ฅธ์ชฝ ๋ฐฉํ–ฅ์œผ๋กœ ํ•ฉํ•ด์„œ ํ•ฉ ๋ฐ˜ํ™˜. start์™€ iterable์˜ ์š”์†Œ๋Š” ์ˆซ์ž๋งŒ ๊ฐ€๋Šฅ

a = [1, 3, 4, 23, 6]
print(sum(a))
# 37
print(sum(a, start=2))
# 39

6. ์ž…์ถœ๋ ฅ

 

- input([prompt])

 : prompt ์ธ์ž๊ฐ€ ์žˆ์œผ๋ฉด ๋์— ๊ฐœํ–‰ ๋ฌธ์ž๋ฅผ ๋ถ™์ด์ง€ ์•Š๊ณ  ํ‘œ์ค€ ์ถœ๋ ฅ์— ์‚ฌ์šฉ. ํ•œ ์ค„์„ ์ž…๋ ฅ๋ฐ›๊ณ  ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜

a = input()
# 
b = input("์ž…๋ ฅํ•˜์„ธ์š” : ")
# ์ž…๋ ฅํ•˜์„ธ์š” : 

 

- print(*objects[, sep=' ', end='\n'])

 : objects ์ถœ๋ ฅ. sep๋กœ ๊ตฌ๋ถ„๋˜๊ณ  ๋’ค์— end๋ฅผ ๋ถ™์ž„

a, b, c = 1, 2, 3
print(a, b, c)
# 1 2 3
print(a, b, c, sep='/', end='///')
# 1/2/3///

7. ๊ธฐํƒ€

 

- eval(expression[, globals[, locals]])

 : ์ธ์ž๋กœ ์ „๋‹ฌ๋œ expression( = ์‹ )์„ ๋ฌธ์ž์—ด๋กœ ๋ฐ›์•„ ์ด๋ฅผ ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ๊ฐ’์„ ๋ฐ˜ํ™˜

print(eval('10 + 123'))
# 133
print(eval('abs(-11)'))
# 11
print(eval('divmod(12, 5)'))
# (2, 2)

 

- format(value[, format_spec])

 : format_spec์— ๋”ฐ๋ผ value๋ฅผ ํฌ๋งท๋œ ํ‘œํ˜„์œผ๋กœ ๋ณ€ํ™˜.

string ๋งํฌ

 

- getattr(object, name[, default])

 : object์˜ name ์–ดํŠธ๋ฆฌ๋ทฐํŠธ๋ฅผ ๋ฐ˜ํ™˜. ( getattr(x, 'foobar') == x.foobar ) ๋ช…๋ช…๋œ ์–ดํŠธ๋ฆฌ๋ทฐํŠธ๊ฐ€ ์—†์œผ๋ฉด default๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ  defalut๊ฐ€ ์ธ์ž๋กœ ์ฃผ์–ด์ง€์ง€ ์•Š์œผ๋ฉด AttributeError ๋ฐœ์ƒ

 

- hasattr(object, name)

 : name์ด object์˜ ์–ดํŠธ๋ฆฌ๋ทฐํŠธ ์ค‘ ํ•˜๋‚˜์˜ ์ด๋ฆ„์ด๋ฉด True, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด False ๋ฐ˜ํ™˜.

  ( getattr(object, name)์„ ํ˜ธ์ถœํ•˜๊ณ  AttributeError๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”์ง€๋ฅผ ๋ณด๋Š” ์‹์œผ๋กœ ๊ตฌํ˜„๋จ )

 

- setattr(object, name, value)

 : ๊ธฐ์กด ์–ดํŠธ๋ฆฌ๋ทฐํŠธ ๋˜๋Š” ์ƒˆ ์–ดํŠธ๋ฆฌ๋ทฐํŠธ์˜ ์ด๋ฆ„์„ ์ง€์ •. ( setattr(x, 'foobar', 123) == x.foobar = 123 )