GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — learn-python/src/functions/test_function_default_arguments.py at master · efr2et/learn-python Expand file tree/ Copy pathtest_function_default_arguments.pyMore file actions 26 lines (18 loc) · 925 Bytes / Copy pathtest_function_default_arguments.pyFile metadata and controls26 lines (18 loc) · 925 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 """Default Argument Values @see: https://docs.python.org/3/tutorial/controlflow.html#default-argument-values The most useful form is to specify a default value for one or more arguments. This creates a function that can be called with fewer arguments than it is defined to allow. """ def power_of(number, power=2): """ Raises number to specific power. You may notice that by default the function raises number to the power of two. """ return number ** power def test_default_function_arguments(): """Test default function arguments""" # This function power_of can be called in several ways because it has default value for # the second argument. First we may call it omitting the second argument at all. assert power_of(3) == 9 # We may also want to override the second argument by using the following function calls. assert power_of(3, 2) == 9 assert power_of(3, 3) == 27 |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |