/ factorpad.com / tech / python / reference / python-keywords.html
An ad-free and cookie-free website.
Beginner
This Python reference offers programmers a quick way to learn Python and also serves as a source for reminders.
While the version documented here is Python 3.5.3, most of this is suitable for other versions of Python 3. Check your version for details.
Keywords in Python are reserved for specific purposes and should not be used when naming objects. Many keywords are used in statements and create blocks of code.
Built-In Constants refer to words used at the Python Interpreter and have special meaning there.
Below are the 33 reserved keywords in Python 3 that should not be used when naming objects.
Keywords | |||
---|---|---|---|
False | def | if | raise |
None | del | import | return |
True | elif | in | try |
and | else | is | while |
as | except | lambda | with |
assert | finally | nonlocal | yield |
break | for | not | |
class | from | or | |
continue | global | pass |
As noted in the previous reference page, entering
help('keywords')
at the Python
Interpreter will print keywords for your specific version.
Taking the list of Python keywords a step further, let's categorize them by Priority so you know which ones to memorize first.
The Statement definition column shows whether the keyword is used to define a specific block of code. Included in parentheses is the statement's purpose.
The Included in column shows contexts where the Python keyword may be used. For example, it may be used as a clause in another statement or block type.
Keyword | Priority | Statement definition (purpose) |
Included in |
---|---|---|---|
False |
High | -- | 1) Boolean operations |
None |
High | NoneType class (null or no value exists) |
-- |
True |
High | -- | 1) Boolean operations |
and |
High | -- | 1) Control flow statements 2) Membership operations 3) Boolean operations |
as |
Mid | -- | 1) import statement2) with statement3) try statement |
assert |
Mid | assert statement(error handling) |
-- |
break |
High | -- | 1) for statement2) while statement3) try statement |
class |
High | class definition(user-defined classes) |
-- |
continue |
High | -- | 1) for statement2) while statement3) try statement |
def |
High | def definition(user-defined functions) |
-- |
del |
High | del statement(remove objects or values) |
-- |
elif |
High | -- | 1) if statement |
else |
High | -- | 1) if statement2) try statement3) while statement4) for statement |
except |
Mid | -- | 1) try statement |
finally |
Mid | -- | 1) try statement |
for |
High | for statement(looping) |
-- |
from |
High | -- | 1) import statement2) yield statement |
global |
Mid | global statement(scope specifications) |
-- |
if |
High | if statement(control flow) |
-- |
import |
High | import statement(external modules) |
-- |
in |
High | -- | 1) for statement2) Membership operations |
is |
High | -- | 1) Comparison operations 2) Membership operations |
lambda |
Low | lambda statement(nameless single-expression function) |
-- |
nonlocal |
Mid | nonlocal statement(scope specifications) |
-- |
not |
High | -- | 1) Control flow statements 2) Membership operations 3) Boolean operations |
or |
High | -- | 1) Control flow statements 2) Membership operations 3) Boolean operations |
pass |
Mid | -- | 1) def definition2) class definition |
raise |
Mid | -- | 1) try statement |
return |
High | -- | 1) def definition2) lambda statement3) try statement |
try |
Mid | try statement(exception handling) |
-- |
while |
High | while statement(looping) |
-- |
with |
Mid | with statement(control flow) |
-- |
yield |
Low | yield statement(iterator functions) |
-- |
At the advanced level, when creating coroutines the words
await
and
async
become reserved keywords.
The Built-In Constants below, when typed at the Python Interpreter have special meaning as well and should only be used for their intended purpose.
Constants | |||
---|---|---|---|
False | NotImplemented | quit() | license |
True | Elipsis or ... | exit() | credits |
None | __debug__ | copyright |
A discussion of selecting text editors and integrated development environments (IDEs) is beyond our scope here certainly. The topic can be a minefield. It become a highly personal choice like selecting a tennis racquet or set of golf clubs. It can take years of experimentation before deciding on the best tool for you.
That said, to avoid being innundated with editor and IDE features
most beginners are advised to start learning Python right in the Python
Interpreter itself, or with a basic text editor pre-packaged with their
operating system. Common choices include Notepad on Windows, TextEdit
on macOS and nano
at the Linux command
line.
See List of text editors at Wikipedia if you have yet to select your editor of choice.
Before you memorize Python keywords and constants it is a good idea to either turn on, or select a text editor with a feature called syntax highlighting. This will highlight keywords in a different color automatically based on the file's extension, like .py for Python scripts.
Subscribe to our growing YouTube Channel, a companion to this free online educational website.
/ factorpad.com / tech / python / reference / python-keywords.html
A newly-updated free resource. Connect and refer a friend today.