Python

[Python] keyword

파이썬에는 키워드 (Keyword)는 이미 예약되어 있는 문자열이 있다.

그렇기 때문에 따로 변수나 함수의 이름 등으로 사용할 수 없다. 만약 변수 이름으로 사용한다면 Syntax Error가 난다.

SyntaxError: invalid syntax

파이썬에 존재하는 33개의 키워드는 아래와 같다.

False, None, True, and, as, assert, 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

 

파이썬에서 키워드를 확인하는 방법

import keyword

print(keyword.kwlist)

# list 형식의 반환
# ['False', 'None', 'True', 'and', 'as', 'assert', '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']

 

reference

https://codetorial.net/python/keywords/index.html