8.2. Builtin Keywords

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

8.2.2. pass

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

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

8.2.3. __file__

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


dir = dirname(__file__)

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


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

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

8.2.4. del

DATA = {
    'firstname': 'Mark',
    'lastname': 'Watney',
}

print(DATA)
# {'firstname': 'Mark', 'lastname': 'Watney'}

del DATA['firstname']

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