FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python/src/functions/test_function_default_arguments.py at master · sobitd/learn-python · GitHub
sobitd
/
learn-python
Public
forked from
trekhleb/learn-python
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python
/
src
/
functions
/
test_function_default_arguments.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (18 loc) · 925 Bytes
Breadcrumbs
learn-python
/
src
/
functions
/
test_function_default_arguments.py
Copy path
File metadata and controls
26 lines (18 loc) · 925 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
Back
|
FazBrowse Home
|
New Git URL