Contents
- Python - 프로그래밍 시작하기
- Python 기초 (Basics)
- Python 변수 (Variables)
- Python 연산자 (Operators)
- Python 리스트 (List)
- Python 튜플 (Tuple)
- Python 문자열 (Strings)
- Python 집합 (Sets)
- Python 딕셔너리 (Dictionary)
- Python 흐름 제어 (Flow control)
- Python 함수 (Function)
- Python 클래스 (Class)
- Python 내장함수 (Built-in function)
- Python 키워드 (Keyword)
- Keyword - and
- Keyword - as
- Keyword - assert
- Keyword - break
- Keyword - class
- Keyword - continue
- Keyword - def
- Keyword - del
- Keyword - elif
- Keyword - else
- Keyword - except
- Keyword - False
- Keyword - for
- Keyword - from
- Keyword - global
- Keyword - if
- Keyword - import
- Keyword - in
- Keyword - is
- Keyword - lambda
- Keyword - None
- Keyword - not
- Keyword - or
- Keyword - pass
- Keyword - return
- Keyword - True
- Keyword - try
- Keyword - while
- Python datetime 모듈
- Python time 모듈
- Python collections.deque 객체
- Python의 선 (Zen of Python)
Tutorials
- Python Tutorial
- NumPy Tutorial
- Matplotlib Tutorial
- PyQt5 Tutorial
- BeautifulSoup Tutorial
- xlrd/xlwt Tutorial
- Pillow Tutorial
- Googletrans Tutorial
- PyWin32 Tutorial
- PyAutoGUI Tutorial
- Pyperclip Tutorial
- TensorFlow Tutorial
- Tips and Examples
Python 내장함수 (Built-in function)¶
파이썬은 언제 어디서나 사용 가능한 다양한 함수를 내장하고 있습니다.
이러한 함수들을 내장함수 (built-in function)라고 하고, 그 목록은 아래와 같습니다.
abs()
all()
any()
ascii()
bin()
bool()
breakpoint()
bytearray()
bytes()
callable()
chr()
classmethod()
compile()
complex()
delattr()
dict()
dir()
divmod()
enumerate()
eval()
exec()
filter()
float()
format()
frozenset()
getattr()
globals()
hasattr()
hash()
help()
hex()
id()
input()
int()
isinstance()
issubclass()
iter()
len()
list()
locals()
map()
max()
memoryview()
min()
next()
object()
oct()
open()
ord()
pow()
print()
property()
range()
repr()
reversed()
round()
set()
setattr()
slice()
sorted()
staticmethod()
str()
sum()
super()
tuple()
type()
vars()
zip()
__import__()
주요한 내장함수에 대한 설명과 예제는 아래를 참고하세요.
abs()¶
절대값을 반환합니다. 정수 또는 부동 소수점 숫자가 될 수 있습니다. 복소수에 대해서는 크기를 반환합니다.
a = -3
b = -1.65
c = 1 - 1j
print(abs(a))
print(abs(b))
print(abs(c))
3
1.65
1.4142135623730951
all()¶
반복 가능한(iterable) 객체의 모든 요소가 True일 때 True를 반환합니다. 빈 객체의 경우 False를 반환합니다.
a = [1, 2, 3]
b = [True, False, True]
c = 'an apple'
print(all(a))
print(all(b))
print(all(c))
True
False
True
any()¶
반복 가능한(iterable) 객체의 요소 중 하나라도 True일 때 True를 반환합니다. 빈 객체의 경우 False를 반환합니다.
a = [1, 0, 3]
b = [False, False, False]
c = (1, 0, 0, 4)
print(any(a))
print(any(b))
print(any(c))
True
False
True
ascii()¶
repr() 처럼, 객체(문자열, 리스트, 튜플, 딕셔너리 등)의 출력 가능한 표현을 포함하는 문자열을 반환합니다.
non-ASCII 문자에 대해서는 x, u, U를 이용해서 이스케이프합니다.
Python 2의 repr()에 의해 반환되는 문자열과 유사하게 문자열을 반환합니다.
a = ascii('Python')
print(a)
b = ascii('Pythön')
print(b)
c = ascii('apple')
print(c)
d = ascii('åpple')
print(d)
'Python'
'Pyth\xf6n'
'apple'
'\xe5pple'
bin()¶
정수를 ‘0b’가 앞에 붙은 이진수 문자열로 변환합니다. 그 결과는 유효한 파이썬 표현입니다.
print(bin(3))
print(bin(-10))
0b11
-0b1010
접두어(0b)가 필요없다면 아래와 같이 format()을 사용할 수 있습니다.
print(format(14, '#b'))
print(format(14, 'b'))
0b1110
1110
bool()¶
논리값, True 또는 False를 반환합니다.
print(bool(3))
print(bool(-1.5))
print(bool(0))
print(bool('apple'))
print(bool(1 <= 3))
print(bool([]))
True
True
False
True
True
False
callable()¶
인자 object가 호출 가능한 것처럼 보이면 True, 그렇지 않으면 False를 반환합니다.
True를 반환하더라도 호출이 실패할 가능성이 있지만, False라면 반드시 호출하지 못합니다.
num = 10
print(callable(num))
def hello():
print('hello')
fun_hello = hello
print(callable(fun_hello))
False
True
chr(i)¶
유니코드 코드 포인트가 정수 i인 문자를 나타내는 문자열을 돌려줍니다.
예를 들어, chr(97)은 ‘a’를 반환하고, chr(8364)는 ‘€’를 반환합니다. 이것은 ord() 의 반대입니다.
complex([real[, imag]])¶
real + imag*1j의 값을 가진 복소수를 반환하거나 문자열 또는 숫자를 복소수로 변환합니다.
a = complex(1, -2)
print(a)
b = complex(1)
print(b)
c = complex()
print(c)
d = complex('5-9j')
print(d)
(1-2j)
(1+0j)
0j
(5-9j)
첫번째 매개변수가 문자열이면 복소수로 해석되며, 두번째 매개변수를 입력하면 안됩니다. 두 번째 매개변수는 결코 문자열 일 수 없습니다.
문자열을 복소수로 변환할 때, 문자열은 중앙의 + 또는 - 연산자 주위에 공백을 포함해서는 안 됩니다.
예를 들어, complex(‘1+2j’)는 괜찮지만 complex(‘1 + 2j’)는 ValueError를 일으킵니다.