what is a function?

A function is code that is callable, this means I can write code to do something one time, and call the name for it to do that thing at a different time from when I write it.

functions can make code simpler, easier to read, test, reuse, maintain and improve - all the good things.


how to make a function

functions are made with

  • the def keyword

  • a name

  • parentheses and a colon at the end

  • the code that makes up the function (its body) comes after the colon

def name_of_function():
    the body of the function
    ...

preview

I have these tests by the end of the chapter

functions/tests/test_functions.py
 1def test_making_a_function_w_pass():
 2    def w_pass():
 3        pass
 4
 5    assert w_pass() is None
 6
 7
 8def test_making_a_function_w_return():
 9    def w_return():
10        return
11
12    assert w_return() is None
13
14
15def test_making_a_function_w_return_none():
16    def w_return_none():
17        return None
18
19    assert w_return_none() is None
20
21
22def test_what_happens_after_functions_return():
23    def return_leaves_the_function():
24        return None
25        return 'only one way for this line to run'
26
27    assert return_leaves_the_function() is None
28
29
30def test_constant_function():
31    def constant():
32        return 'the same thing'
33
34    assert constant() == 'the same thing'
35
36
37# Exceptions seen
38# AssertionError
39# NameError
40# TypeError

questions about functions

Questions to think about as I go through the chapter


start the project

  • I name this project functions

  • I open a terminal

  • I use uv to make a directory for the project and initialize it

    uv init functions
    

    the terminal shows

    Initialized project `functions`
    at `.../pumping_python/functions`
    

    then goes back to the command line.

  • I change directory to the project

    cd functions
    

    the terminal shows I am in the functions folder

    .../pumping_python/functions
    
  • I make a directory for the tests

    mkdir tests
    

    the terminal goes back to the command line.

  • I make the tests directory a Python package

    Danger

    use 2 underscores (__) before and after init for __init__.py not _init_.py

    touch tests/__init__.py
    
    New-Item tests/__init__.py
    

    the terminal goes back to the command line.

  • I use the mv program to change the name of main.py to test_functions.py and move it to the tests folder

    mv main.py tests/test_functions.py
    
    Move-Item main.py tests/test_functions.py
    

    the terminal goes back to the command line.

  • I open test_functions.py

  • I delete all the text then add the first failing test to test_functions.py

    1def test_failure():
    2    assert False is True
    
  • I go back to the terminal to make a requirements file for the Python packages I need

    echo "pytest" > requirements.txt
    

    the terminal goes back to the command line.

  • I add pytest-watcher to the requirements file

    echo "pytest-watcher" >> requirements.txt
    

    the terminal goes back to the command line.

  • I use uv to install pytest-watcher with the requirements file

    uv add --requirement requirements.txt
    

    the terminal shows that it installed pytest-watcher and its dependencies.

  • I add the new files and folders to git for tracking

    git add .
    

    the terminal goes back to the command line.

  • I add a git commit message

    git commit --all --message 'setup project'
    

    the terminal shows

    [main (root-commit) a0b12c3] setup project
     8 files changed, X insertions(+)
     create mode 100644 .gitignore
     create mode 100644 .python-version
     create mode 100644 README.md
     create mode 100644 pyproject.toml
     create mode 100644 requirements.txt
     create mode 100644 tests/__init__.py
     create mode 100644 tests/test_functions.py
     create mode 100644 uv.lock
    

    then goes back to the command line.

  • I use pytest-watcher to run the tests automatically

    uv run pytest-watcher . --now
    

    the terminal is my friend, and shows AssertionError

    ======================== FAILURES ========================
    ______________________ test_failure ______________________
    
        def test_failure():
    >       assert False is True
    E       assert False is True
    
    test_functions.py:2: AssertionError
    ================ short test summary info =================
    FAILED test_functions.py::test_failure - assert False is True
    =================== 1 failed in X.YZs ====================
    

    because False is NOT True

    if the terminal does not show the same error, then check if

    • your tests/__init__.py has two underscores (__) before and after init for __init__.py not _init_.py

    • you ran echo "pytest-watcher" >> requirements.txt, to add pytest-watcher to the requirements file

    and try uv run pytest-watcher . --now again

  • I add AssertionError to the list of Exceptions seen, in test_functions.py

    1def test_failure():
    2    assert False is True
    3
    4
    5# Exceptions seen
    6# AssertionError
    
  • I change True to False in the assertion

    1def test_failure():
    2    # assert False is True
    3    assert False is False
    4
    5
    6# Exceptions seen
    7# AssertionError
    

    the test passes.


test_making_a_function_w_pass

The simplest function I can make is with the pass keyword.


RED: make it fail


  • I change test_failure to test_making_a_function_w_pass

    1def test_making_a_function_w_pass():
    2    w_pass
    3
    4
    5# Exceptions seen
    6# AssertionError
    

    the terminal is my friend, and shows NameError

    >       w_pass
    E       NameError: name 'w_pass' is not defined
    

    because Python does not know what I mean by w_pass since I do not have a definition for it in test_functions.py.

  • I add NameError to the list of Exceptions seen

    5# Exceptions seen
    6# AssertionError
    7# NameError
    

what is a variable?

I can define a name in Python with a variable. A variable is a name that is used to point to an object. For example, in Mathematics we use x to represent any number.

Every time I use the name, Python “knows” that I am referring to the object pointed the name to.


GREEN: make it pass


I change w_pass to a variable by pointing it to None (the simplest object)

1def test_making_a_function_w_pass():
2    # w_pass
3    w_pass = None
4
5
6# Exceptions seen
7# AssertionError
8# NameError

the test passes.


REFACTOR: make it better



how to call a function

I can call a function with by placing parentheses (()) after the name when I use it after it is defined.

name_of_function()

A call to a function gets the output of the function

name_of_function() -> output_object

RED: make it fail


  • I add parentheses to the assertion to call w_pass inside test_making_a_function_w_pass

    1def test_making_a_function_w_pass():
    2    # w_pass
    3    w_pass = None
    4    # assert w_pass is 0
    5    # assert w_pass is None
    6    assert w_pass() is None
    7
    8
    9# Exceptions seen
    

    the terminal is my friend, and shows TypeError

    TypeError: 'NoneType' object is not callable
    

    because the assertion calls w_pass which points to None and I cannot call None like a function. Using substitution

    w_pass = None # point the name to the object
    w_pass()      # call the name
    None()        # substitute the value for the name
    

    None() raises TypeError.

  • I add TypeError to the list of Exceptions seen

     9# Exceptions seen
    10# AssertionError
    11# NameError
    12# TypeError
    

GREEN: make it pass



REFACTOR: make it better


  • I remove the commented lines

     1def test_making_a_function_w_pass():
     2    def w_pass():
     3        pass
     4
     5    assert w_pass() is None
     6
     7
     8# Exceptions seen
     9# AssertionError
    10# NameError
    11# TypeError
    
  • I open another terminal then change directory to functions

    cd functions
    
  • I add a git commit message

    git commit --all --message \
    'add test_making_a_function_w_pass'
    

    the terminal shows a summary of the changes then goes back to the command line.

I can make a function with pass..


test_making_a_function_w_return

I can also make a function with a return statement.


RED: make it fail


  • I go back to the terminal where the tests are running

  • I add a new test with a name

     1def test_making_a_function_w_pass():
     2    def w_pass():
     3        pass
     4
     5    assert w_pass() is None
     6
     7
     8def test_making_a_function_w_return():
     9    w_return
    10
    11
    12# Exceptions seen
    

    the terminal is my friend, and shows NameError

    >       w_return
    E       NameError: name 'w_return' is not defined
    

    because Python does not know what I mean by w_return since I do not have a definition for it in test_functions.py.


GREEN: make it pass


I change w_return to a variable by pointing it to None (the simplest object)

 8def test_making_a_function_w_return():
 9    # w_return
10    w_return = None
11
12
13# Exceptions seen

the test passes.


REFACTOR: make it better


  • I add an assertion for w_return

     8def test_making_a_function_w_return():
     9    # w_return
    10    w_return = None
    11    assert w_return is 1
    12
    13
    14# Exceptions seen
    

    the terminal is my friend, and shows AssertionError

    E       assert None is 1
    

    because w_return points to None. Using substitution

    w_return = None
    assert w_return is 1
    assert None     is 1
    

    which raises AssertionError since None is not the same object as an integer (whole number without decimals).

  • I change the assertion to make the statement True

     8def test_making_a_function_w_return():
     9    # w_return
    10    w_return = None
    11    # assert w_return is 1
    12    assert w_return is None
    13
    14
    15# Exceptions seen
    

    the test passes.

  • I add parentheses to call w_return inside test_making_a_function_w_return

     8def test_making_a_function_w_return():
     9    # w_return
    10    w_return = None
    11    # assert w_return is 1
    12    # assert w_return is None
    13    assert w_return() is None
    14
    15
    16# Exceptions seen
    

    the terminal is my friend, and shows TypeError

    TypeError: 'NoneType' object is not callable
    

    because the assertion calls w_return which points to None and I cannot call None like a function. Using substitution

    w_return = None # point the name to the object
    w_return()      # call the name
    None()          # substitute the value for the name
    

    None() raises TypeError.

  • I use the def and pass keywords to change w_return to the simplest function I can make

     8def test_making_a_function_w_return():
     9    # w_return
    10    # w_return = None
    11    # assert w_return is 1
    12    # assert w_return is None
    13    def w_return():
    14        pass
    15
    16    assert w_return() is None
    17
    18
    19# Exceptions seen
    

    the test passes.


the return statement

The return keyword is used to define what a function gives as output when it is called.

  • I change pass to a return statement with the return keyword

     8def test_making_a_function_w_return():
     9    # w_return
    10    # w_return = None
    11    # assert w_return is 1
    12    # assert w_return is None
    13    def w_return():
    14        # pass
    15        return
    16
    17    assert w_return() is None
    18
    19
    20# Exceptions seen
    
    • The test is still green because I get None when I call<how to call a function>```w_return`

      w_return() -> None
      
    • The assertion - assert w_return() is None checks if the result of a call to w_return, is the same object as None.

    • The function definition simply says return and the test passes.

    • return is a keyword that defines what the function gives as output.

  • I remove the commented lines

     1def test_making_a_function_w_pass():
     2    def w_pass():
     3        pass
     4
     5    assert w_pass() is None
     6
     7
     8def test_making_a_function_w_return():
     9    def w_return():
    10        return
    11
    12    assert w_return() is None
    13
    14
    15# Exceptions seen
    
  • I add a git commit message in the other terminal

    git commit --all --message \
    'add test_making_a_function_w_return'
    

    the terminal shows a summary of the changes then goes back to the command line.

I can make a function with a return statement.

I have two functions with different statements, and the tests show that they both return None

def w_pass():
    pass
def w_return():
    return

their contents are different, their results are the same because “all functions return None by default, as if they have an invisible line that says return None”, which leads me to the next test.


test_making_a_function_w_return_none

I can make a function with a return statement that says exactly what the function returns.


RED: make it fail


  • I go back to the terminal where the tests are running

  • I add a test with a name

     8def test_making_a_function_w_return():
     9    def w_return():
    10        return
    11
    12    assert w_return() is None
    13
    14
    15def test_making_a_function_w_return_none():
    16    w_return_none
    17
    18
    19# Exceptions seen
    

    the terminal is my friend, and shows NameError

    NameError: name 'w_return_none' is not defined
    

    because Python does not know what I mean by w_return_none since I do not have a definition for it in this file.


GREEN: make it pass


I change w_return_none to a variable by pointing it to None (the simplest object)

15def test_making_a_function_w_return_none():
16    # w_return_none
17    w_return_none = None
18
19
20# Exceptions seen

the test passes.


REFACTOR: make it better


  • I add an assertion for w_return_none

    15def test_making_a_function_w_return_none():
    16    # w_return_none
    17    w_return_none = None
    18    assert w_return_none is 2
    19
    20
    21# Exceptions seen
    

    the terminal is my friend, and shows AssertionError

    E       assert None is 2
    

    because w_return_none points to None. Using substitution

    w_return_none = None
    assert w_return_none is 2
    assert None          is 2
    

    which raises AssertionError since None is not the same object as an integer (a whole number without decimals).

  • I change the assertion to make the statement True

    15def test_making_a_function_w_return_none():
    16    # w_return_none
    17    w_return_none = None
    18    # assert w_return_none is 2
    19    assert w_return_none is None
    20
    21
    22# Exceptions seen
    

    the test passes.

  • I add parentheses to call w_return_none inside test_making_a_function_w_return_none

    15def test_making_a_function_w_return_none():
    16    # w_return_none
    17    w_return_none = None
    18    # assert w_return_none is 2
    19    # assert w_return_none is None
    20    assert w_return_none() is None
    21
    22
    23# Exceptions seen
    

    the terminal is my friend, and shows TypeError

    TypeError: 'NoneType' object is not callable
    

    because the assertion calls w_return_none which points to None and I cannot call None like a function. Using substitution

    w_return_none = None # point the name to the object
    w_return_none()      # call the name
    None()               # substitute the value for the name
    

    None() raises TypeError.

  • I change w_return_none to a function with the def and return keywords

    15def test_making_a_function_w_return_none():
    16    # w_return_none
    17    # w_return_none = None
    18    # assert w_return_none is 2
    19    # assert w_return_none is None
    20    def w_return_none():
    21        return
    22
    23    assert w_return_none() is None
    24
    25
    26# Exceptions seen
    

    the test passes.

  • I add None to the return statement of w_return_none

    15def test_making_a_function_w_return_none():
    16    # w_return_none
    17    # w_return_none = None
    18    # assert w_return_none is 2
    19    # assert w_return_none is None
    20    def w_return_none():
    21        # return
    22        return None
    23
    24    assert w_return_none() is None
    25
    26
    27# Exceptions seen
    

    the test is still green.

  • I change None to 'something'

    15def test_making_a_function_w_return_none():
    16    # w_return_none
    17    # w_return_none = None
    18    # assert w_return_none is 2
    19    # assert w_return_none is None
    20    def w_return_none():
    21        # return
    22        # return None
    23        return 'something'
    24
    25    assert w_return_none() is None
    26
    27
    28# Exceptions seen
    

    the terminal is my friend, and shows AssertionError

    AssertionError: assert 'something' is None
    

    because I get 'something' when I call w_return_none

    w_return_none() -> None
    

    Using substitution

    assert w_return_none() is None
    assert 'something'     is None
    

    which raises AssertionError because a string (anything in quotes) is not None.

  • I undo the change

    18def test_making_a_function_w_return_none():
    19    # w_return_none
    20    # w_return_none = None
    21    # assert w_return_none is 2
    22    # assert w_return_none is None
    23    def w_return_none():
    24        # return
    25        return None
    26        # return 'something'
    27
    28    assert w_return_none() is None
    29
    30
    31# Exceptions seen
    
    • The test is green again because I get None when I call w_return_none.

    • The assertion - assert w_return_none() is None checks if the result of a call to w_return_none, is the same object as None.

  • I remove the commented lines

     8def test_making_a_function_w_return():
     9    def w_return():
    10        return
    11
    12    assert w_return() is None
    13
    14
    15def test_making_a_function_w_return_none():
    16    def w_return_none():
    17        return None
    18
    19    assert w_return_none() is None
    20
    21
    22# Exceptions seen
    
  • I add a git commit message in the other terminal

    git commit --all --message \
    'add test_making_a_function_w_return_none'
    

    the terminal shows a summary of the changes then goes back to the command line.

I can make a function with return None..

I have three functions with different statements, and the tests show that they all return None

def w_pass():
    pass
def w_return():
    return
def w_return_none():
    return None

their contents are different, their results are the same because “all functions return None by default, as if they have an invisible line that says …

I like to write my functions with explicit return statements, so that anyone can see what the function returns without having to think about it.


test_what_happens_after_functions_return

The return statement is the last thing to run in a function.


RED: make it fail


  • I go back to the terminal where the tests are running

  • I add a test to test_functions.py

    15def test_making_a_function_w_return_none():
    16    def w_return_none():
    17        return None
    18
    19    assert w_return_none() is None
    20
    21
    22def test_what_happens_after_functions_return():
    23    return_leaves_the_function
    24
    25
    26# Exceptions seen
    

    the terminal is my friend, and shows NameError

    NameError: name 'return_leaves_the_function'
               is not defined
    

    because Python does not know what I mean by return_leaves_the_function since I do not have a definition for it in this file, yet.


GREEN: make it pass


I change return_leaves_the_function to a variable by pointing it to None (the simplest object)

22def test_what_happens_after_functions_return():
23    # return_leaves_the_function
24    return_leaves_the_function = None
25
26
27# Exceptions seen

the test passes.


REFACTOR: make it better


  • I add an assertion

    22def test_what_happens_after_functions_return():
    23    # return_leaves_the_function
    24    return_leaves_the_function = None
    25    assert return_leaves_the_function is 'something'
    26
    27
    28# Exceptions seen
    

    the terminal is my friend, and shows AssertionError

    AssertionError: assert None is 'something'
    

    because return_leaves_the_function points to None. Using substitution

    return_leaves_the_function = None
    assert return_leaves_the_function is 'something'
    assert None                       is 'something'
    

    which raises AssertionError since None is not the same object as a string.

  • I change the assertion to make the statement True

    22def test_what_happens_after_functions_return():
    23    # return_leaves_the_function
    24    return_leaves_the_function = None
    25    # assert return_leaves_the_function is 'something'
    26    assert return_leaves_the_function is None
    27
    28
    29# Exceptions seen
    

    the test passes.

  • I add parentheses to call return_leaves_the_function inside test_making_a_function_w_return_none

    22def test_what_happens_after_functions_return():
    23    # return_leaves_the_function
    24    return_leaves_the_function = None
    25    # assert return_leaves_the_function is 'something'
    26    # assert return_leaves_the_function is None
    27    assert return_leaves_the_function() is None
    28
    29
    30# Exceptions seen
    

    the terminal is my friend, and shows TypeError

    TypeError: 'NoneType' object is not callable
    

    because the assertion calls return_leaves_the_function which points to None and I cannot call None like a function. Using substitution

    return_leaves_the_function = None # point the name to the object
    return_leaves_the_function()      # call the name
    None()                            # substitute the value for the name
    

    None() raises TypeError.

  • I change return_leaves_the_function to a function with the def and return keywords

    22def test_what_happens_after_functions_return():
    23    # return_leaves_the_function
    24    # return_leaves_the_function = None
    25    # assert return_leaves_the_function is 'something'
    26    # assert return_leaves_the_function is None
    27    def return_leaves_the_function():
    28        return None
    29
    30    assert return_leaves_the_function() is None
    31
    32
    33# Exceptions seen
    

    the test passes.

  • I add a return statement

    22def test_what_happens_after_functions_return():
    23    # return_leaves_the_function
    24    # return_leaves_the_function = None
    25    # assert return_leaves_the_function is 'something'
    26    # assert return_leaves_the_function is None
    27    def return_leaves_the_function():
    28        return 'something'
    29        return None
    30
    31    assert return_leaves_the_function() is None
    32
    33
    34# Exceptions seen
    

    the terminal is my friend, and shows AssertionError

    E       AssertionError: assert 'something' is None
    

    because I get 'something' when I call return_leaves_the_function

    w_return_leaves_the_function() -> 'something'
    

    Using substitution

    assert return_leaves_the_function() is None
    assert 'something'                  is None
    

    Tip

    The Integrated Development Environment (IDE) shows that the second return statement will not run by graying it out.

  • I move return None, to make it the first return statement

    22def test_what_happens_after_functions_return():
    23    # return_leaves_the_function
    24    # return_leaves_the_function = None
    25    # assert return_leaves_the_function is 'something'
    26    # assert return_leaves_the_function is None
    27    def return_leaves_the_function():
    28        return None
    29        return 'something'
    30
    31    assert return_leaves_the_function() is None
    32
    33
    34# Exceptions seen
    

    the test is green again.

  • I change the second return statement as a reminder

    22def test_what_happens_after_functions_return():
    23    # return_leaves_the_function
    24    # return_leaves_the_function = None
    25    # assert return_leaves_the_function is 'something'
    26    # assert return_leaves_the_function is None
    27    def return_leaves_the_function():
    28        return None
    29        # return 'something'
    30        return 'only one way for this line to run'
    31
    32    assert return_leaves_the_function() is None
    33
    34
    35# Exceptions seen
    

    the second return statement is now like a comment, and the test is still green because the return statement is the last thing to run in a function.

  • I remove the commented lines

    15def test_making_a_function_w_return_none():
    16    def w_return_none():
    17        return None
    18
    19    assert w_return_none() is None
    20
    21
    22def test_what_happens_after_functions_return():
    23    def return_leaves_the_function():
    24        return None
    25        return 'only one way for this line to run'
    26
    27    assert return_leaves_the_function() is None
    28
    29
    30# Exceptions seen
    
  • I add a git commit message in the other terminal

    git commit --all --message \
    'add test_what_happens_after_functions_return'
    

    the terminal shows a summary of the changes then goes back to the command line.


test_constant_function

There are functions that always return the same thing when they are called. They are singletons or constant functions.


RED: make it fail


  • I go back to the terminal where the tests are running

  • I add a test

    22def test_what_happens_after_functions_return():
    23    def return_leaves_the_function():
    24        return None
    25        return 'only one way for this line to run'
    26
    27    assert return_leaves_the_function() is None
    28
    29
    30def test_constant_function():
    31    constant
    32
    33
    34# Exceptions seen
    

    the terminal is my friend, and shows NameError

    NameError: name 'constant' is not defined
    

    because Python does not know what I mean by constant since I do not have a definition for it in this file.


GREEN: make it pass


I change constant to a variable by pointing it to None

30def test_constant_function():
31    # constant
32    constant = None
33
34
35# Exceptions seen

the test passes.


REFACTOR: make it better


  • I add an assertion

    30def test_constant_function():
    31    # constant
    32    constant = None
    33    assert constant is 'the same thing'
    34
    35
    36# Exceptions seen
    

    the terminal is my friend, and shows AssertionError

    AssertionError: assert None is 'the same thing'
    

    because constant points to None. Using substitution since I can treat a call to a function as the object it returns

    constant = None
    assert constant is 'the same thing'
    assert None     is 'the same thing'
    

    which raises AssertionError since None is not the same object as a string(anything in quotes).

  • I change the assertion to make the statement True

    30def test_constant_function():
    31    # constant
    32    constant = None
    33    # assert constant is 'the same thing'
    34    assert constant is None
    35
    36
    37# Exceptions seen
    

    the test passes.

  • I add parentheses to call constant

    30def test_constant_function():
    31    # constant
    32    constant = None
    33    # assert constant is 'the same thing'
    34    # assert constant is None
    35    assert constant() is None
    36
    37
    38# Exceptions seen
    

    the terminal is my friend, and shows TypeError

    TypeError: 'NoneType' object is not callable
    

    because the assertion calls constant which points to None and I cannot call None like a function. Using substitution since I can treat a call to a function as the object it returns

    constant = None # point the name to the object
    constant()      # call the name
    None()          # substitute the value for the name
    

    None() raises TypeError.

  • I change constant to a function with the def and return keywords

    30def test_constant_function():
    31    # constant
    32    # constant = None
    33    # assert constant is 'the same thing'
    34    # assert constant is None
    35    def constant():
    36        return None
    37
    38    assert constant() is None
    39
    40
    41# Exceptions seen
    

    the test passes.

  • I change the return statement

    30def test_constant_function():
    31    # constant
    32    # constant = None
    33    # assert constant is 'the same thing'
    34    # assert constant is None
    35    def constant():
    36        # return None
    37        return 'the same thing'
    38
    39    assert constant() is None
    40
    41
    42# Exceptions seen
    

    the terminal is my friend, and shows AssertionError

    AssertionError: assert 'the same thing' is None
    
  • I change the assertion to make it True

    30def test_constant_function():
    31    # constant
    32    # constant = None
    33    # assert constant is 'the same thing'
    34    # assert constant is None
    35    def constant():
    36        # return None
    37        return 'the same thing'
    38
    39    # assert constant() is None
    40    assert constant() == 'the same thing'
    41
    42
    43# Exceptions seen
    

    the test passes because I get 'the same thing' when I call constant

    constant() -> 'the same thing'
    
  • I remove the commented lines

    22def test_what_happens_after_functions_return():
    23    def return_leaves_the_function():
    24        return None
    25        return 'only one way for this line to run'
    26
    27    assert return_leaves_the_function() is None
    28
    29
    30def test_constant_function():
    31    def constant():
    32        return 'the same thing'
    33
    34    assert constant() == 'the same thing'
    35
    36
    37# Exceptions seen
    38# AssertionError
    39# NameError
    40# TypeError
    
  • I add a git commit message in the other terminal

    git commit --all --message 'add test_constant_function'
    

    the terminal shows a summary of the changes then goes back to the command line.

A constant function always returns the same thing. when called, I can use them in place of variables. The number of cases where they are faster than variables is pretty small. It is something like if the function is called less than 10 times (who’s counting?)

All the functions I have written so far return the same value every time they are called.


close the project

  • I close test_functions.py and functions.py

  • I click in the terminal where the tests are running

  • I use q on the keyboard to leave the tests. The terminal goes back to the command line.

  • I change directory to the parent of functions

    cd ..
    

    the terminal shows

    .../pumping_python
    

    I am back in the pumping_python directory.


review

I ran tests to show that I can make functions with the def, pass and return keywords.

How many questions can you answer about functions?


code from the chapter

Do you want to see all the CODE I typed in this chapter?


what is next?

Would you like to make a person with strings?


rate pumping python

If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too.