7.2. Builtin Keywords

7.2.1. List of keywords

import keyword

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']

7.2.2. pass

  • Avoid error when you don't specify the body of a block

Listing 7.6. Exceptions has all the content needed inherited from Exception class. You need something to avoid IndentationError
class MyError(Exception):


print('hello')
# Traceback (most recent call last):
#     ...
# IndentationError: expected an indented block
class MyError(Exception):
    pass


print('hello')
# hello

7.2.3. __file__

print(__file__)
# /home/twardowski/bin/myfile.py
from os.path import dirname


dir = dirname(__file__)

print(f'Working directory: {dir}')
# Working directory: /home/twardowski/bin
from os.path import dirname, join


dir = dirname(__file__)
path = join(dir, 'main.py')

print(f'My file: {path}')
# My file: /home/twardowski/bin/main.py

7.2.4. del

DATA = {
    'firstname': 'Jan',
    'lastname': 'Twardowski',
}

print(DATA)
# {'firstname': 'Jan', 'lastname': 'Twardowski'}

del DATA['firstname']

print(DATA)
# {'lastname': 'Twardowski'}