예약어 (Reserved word, keyword)
특정 기능을 수행하도록 미리 예약되어 있는 단어로 Python 3.10.5 기준으로 35개의 예약어가 있다.
예약어는 대소문자를 구분하며 True, False, None 이외의 예약어는 전부 소문자로 이루어져있다.
예약어는 변수 이름이나 메소드 이름 등 식별자로 사용할 수 없다.
print(len(keyword.kwlist)) #35
예약어는 keword.kwlist로 확인할 수 있다.
len()으로 현재버전의 파이썬 예약어는 35개임을 확인했다.
print(keyword.kwlist)
#['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await',
# 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except',
# 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda',
# 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
예약어 목록을 출력할 수 있다.
True
False
None
and
not
or
as
assert
async
await
break
class
continue
def
del
if
elif
else
is
except
finally
for, while
from
global
import
in
lambda
nonlocal
pass
raise
return
try
with
yield
'Language > Python' 카테고리의 다른 글
파이썬 리스트 중복 요소 개수 찾기 (카운트) , 중복요소 제거하기 (0) | 2022.07.21 |
---|---|
논리연산자의 단축평가 (1) | 2022.07.19 |
파이썬 String Interpolation (문자열 보간) - %, format, f-strings (1) | 2022.07.19 |
파이썬 컨테이너 - 리스트, 튜플, 레인지, 세트, 딕셔너리 (1) | 2022.07.18 |
파이썬 형 변환 (Typecasting - implicit, explicit) (1) | 2022.07.18 |