FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python_koans/python2/koans/about_lambdas.py at master · kolapsys/python_koans · GitHub
kolapsys
/
python_koans
Public
forked from
gregmalcolm/python_koans
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python_koans
/
python2
/
koans
/
about_lambdas.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (20 loc) · 834 Bytes
Breadcrumbs
python_koans
/
python2
/
koans
/
about_lambdas.py
Copy path
File metadata and controls
29 lines (20 loc) · 834 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
27
28
29
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Based slightly on the lambdas section of AboutBlocks in the Ruby Koans
#
from
runner
.
koan
import
*
class
AboutLambdas
(
Koan
):
def
test_lambdas_can_be_assigned_to_variables_and_called_explicitly
(
self
):
add_one
=
lambda
n
:
n
+
1
self
.
assertEqual
(
__
,
add_one
(
10
))
# ------------------------------------------------------------------
def
make_order
(
self
,
order
):
return
lambda
qty
:
str
(
qty
)
+
" "
+
order
+
"s"
def
test_accessing_lambda_via_assignment
(
self
):
sausages
=
self
.
make_order
(
'sausage'
)
eggs
=
self
.
make_order
(
'egg'
)
self
.
assertEqual
(
__
,
sausages
(
3
))
self
.
assertEqual
(
__
,
eggs
(
2
))
def
test_accessing_lambda_without_assignment
(
self
):
self
.
assertEqual
(
__
,
self
.
make_order
(
'spam'
)(
39823
))
Back
|
FazBrowse Home
|
New Git URL