Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a9d825c

Browse files
authoredJun 8, 2022
Merge pull request #90 from jetbrains-academy/sofia/add_docstrings_task
added docstrings task
2 parents 49a8cde + 8911f8f commit a9d825c

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed
 

‎Functions/Docstrings/__init__.py

Whitespace-only changes.

‎Functions/Docstrings/task-info.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type: edu
2+
files:
3+
- name: task.py
4+
visible: true
5+
placeholders:
6+
- offset: 32
7+
length: 54
8+
placeholder_text: '# TODO: add a docstring here'
9+
- name: tests/test_task.py
10+
visible: false
11+
- name: __init__.py
12+
visible: false
13+
- name: tests/__init__.py
14+
visible: false
15+
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Functions+/+Docstrings

‎Functions/Docstrings/task.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Docstrings
2+
3+
One-line docstrings are for really obvious cases. Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description.
4+
The docstring for a function or method should summarize its behavior and document its arguments, return value(s), side effects, exceptions raised, and restrictions on when it can be called (all if applicable). Optional arguments should be indicated. It should be documented whether keyword arguments are part of the interface.
5+
6+
7+
Docstrings should also generally be written for modules, classes and methods definitions (you will learn about these things later on in the course). Read more about docstring conventions in the [Python PEP Guide](https://peps.python.org/pep-0257/).
8+
9+
### Task
10+
Add the following docstring to the function defined in the code editor:
11+
```text
12+
"""This function adds 1 to each element of the list"""
13+
```

‎Functions/Docstrings/task.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def increment_list(mylist):
2+
"""This function adds 1 to each element of the list"""
3+
4+
for i in range(len(mylist)):
5+
mylist[i] += 1
6+
7+
return mylist
8+
9+
10+
print(increment_list.__doc__)
11+
print(increment_list([1, 2, 3]))

‎Functions/Docstrings/tests/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
3+
from task import increment_list
4+
5+
6+
class TestCase(unittest.TestCase):
7+
def test_doc(self):
8+
self.assertNotEqual(increment_list.__doc__, None, msg="Add the docstring to the function.")
9+
self.assertEqual(increment_list.__doc__, "This function adds 1 to each element of the list", msg="The "
10+
"docstring "
11+
"seems to be "
12+
"different.")

‎Functions/lesson-info.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ content:
22
- Definition
33
- Parameters and call arguments
44
- Return value
5+
- Docstrings
56
- Default parameters
67
- Keyword Arguments
78
- Argument Order

0 commit comments

Comments
 (0)
Please sign in to comment.