Skip to content

Commit b6ea39b

Browse files
authored
[Basics, Conditionals, and List Methods]: Corrected Typos, Formatting, & Grammar Issues (exercism#4179)
* Corrected typos, formatting, and grammar issues for basics, conditionals, and list-methods. * Further corrections from code review. * More typos. * Fixed double quote issue.
1 parent 1c9b44c commit b6ea39b

6 files changed

Lines changed: 135 additions & 117 deletions

File tree

concepts/basics/about.md

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ For example, `my_first_variable` can be re-assigned many times using `=`, and ca
6464
>>> print(my_first_variable)
6565
2
6666

67-
>>> my_first_variable = "Now, I'm a string." # You may re-bind a name to a different object type and value.
67+
>>> my_first_variable = "Now, I'm a string." # <--You may re-bind a name to a different object type and value.
6868
>>> print(type(my_first_variable))
6969
<class 'str'>
7070

71-
>>> my_first_variable = 'You can call me "str".' # Strings can be declared using single or double quote marks.
71+
>>> my_first_variable = 'You can call me "str".' # <--Strings can be declared using single or double quote marks.
7272
>>> print(my_first_variable)
7373
You can call me "str".
7474

75-
import collections
76-
>>> my_first_variable = collections.Counter([1,1,2,3,3,3,4,5,6,7]) # Now my_first_variable has been re-bound to a Counter object.
75+
>>> import collections
76+
>>> my_first_variable = collections.Counter([1,1,2,3,3,3,4,5,6,7]) # <--Now my_first_variable has been re-bound to a Counter object.
7777
>>> print(type(my_first_variable))
7878
<class 'collections.Counter'>
7979

@@ -102,7 +102,7 @@ MY_FIRST_CONSTANT = "Some other value"
102102

103103
## Functions
104104

105-
In Python, units of functionality are encapsulated in [_functions._][functions], which are themselves [objects][objects] (_it's [turtles all the way down][turtles all the way down]_).
105+
In Python, units of functionality are encapsulated in [_functions_][functions], which are themselves [objects][objects] (_it's [turtles all the way down][turtles all the way down]_).
106106

107107
Functions can be executed by themselves, passed as arguments to other functions, nested, or bound to a class.
108108
When functions are bound to a [class][classes] name, they're referred to as [methods][method objects].
@@ -114,7 +114,7 @@ Statements for the _body_ of the function begin on the line following `def` and
114114

115115

116116
```python
117-
# The body of a function is indented by 2 spaces, & prints the sum of the numbers.
117+
# The body of a function is indented by 2 spaces & prints the sum of the numbers.
118118
def add_two_numbers(number_one, number_two):
119119
total = number_one + number_two
120120
print(total)
@@ -126,7 +126,7 @@ def add_two_numbers(number_one, number_two):
126126
# Inconsistent indentation in your code blocks will raise an error.
127127
>>> def add_three_numbers_misformatted(number_one, number_two, number_three):
128128
... result = number_one + number_two + number_three # This was indented by 4 spaces.
129-
... print(result) #this was only indented by 3 spaces
129+
... print(result) # <--This was only indented by 3 spaces.
130130
...
131131
...
132132
File "<stdin>", line 3
@@ -157,7 +157,7 @@ def add_two_numbers(number_one, number_two):
157157
```
158158

159159
Functions that do not have an _explicit_ expression following a `return` will _implicitly_ return the [`None`][none] object.
160-
The details of `None` will be covered in a later exercise.
160+
The details of `None` will be covered in a later concept.
161161
For the purposes of this exercise and explanation, `None` is a placeholder that represents nothing, or null:
162162

163163

@@ -208,7 +208,7 @@ Dot (`.`) notation is used for calling functions defined inside a class or modul
208208

209209
```python
210210
>>> def raise_to_power(number, power):
211-
return number ** power
211+
... return number ** power
212212
...
213213

214214
>>> raise_to_power(3,3) # Invoking the function with the arguments 3 and 3.
@@ -225,12 +225,12 @@ TypeError: raise_to_power() missing 1 required positional argument: 'power'
225225

226226
# Calling methods or functions in classes and modules.
227227
>>> start_text = "my silly sentence for examples."
228-
>>> str.upper(start_text) # Calling the upper() method from the built-in str class on start_text.
228+
>>> str.upper(start_text) # <--Calling the upper() method from the built-in str class on start_text.
229229
'MY SILLY SENTENCE FOR EXAMPLES.'
230230

231231
# Because a string is an instance of the str class, methods can also be called on them "directly".
232232
>>> start_text = "my silly sentence for examples."
233-
>>> start_text.upper() # Calling the upper() method on start_text directly.
233+
>>> start_text.upper() # <--Calling the upper() method on start_text directly.
234234
'MY SILLY SENTENCE FOR EXAMPLES.'
235235

236236
# Alternatively, we can skip the variable assignment (although this gets messy quick).
@@ -239,9 +239,8 @@ TypeError: raise_to_power() missing 1 required positional argument: 'power'
239239

240240

241241
# Importing the math module
242-
import math
243-
244-
>>> math.pow(2,4) # Calling the pow() function from the math module
242+
>>> import math
243+
>>> math.pow(2,4) # <--Calling the pow() function from the math module.
245244
16.0
246245
```
247246

@@ -273,14 +272,18 @@ Docstrings are declared using triple double quotes (""") indented at the same le
273272

274273

275274
```python
275+
# An example from PEP257 of a multi-line docstring
276+
# reformatted to use Google style non-type hinted docstrings.
277+
# Some additional details can be found in the Sphinx documentation:
278+
# https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#getting-started
276279

277-
# An example from PEP257 of a multi-line docstring.
278280
def complex(real=0.0, imag=0.0):
279281
"""Form a complex number.
280282
281-
Keyword arguments:
282-
real -- the real part (default 0.0)
283-
imag -- the imaginary part (default 0.0)
283+
Keyword Arguments:
284+
real (float): The real part of the number (default 0.0)
285+
imag (float): The imaginary part of the number (default 0.0)
286+
284287
"""
285288

286289
if imag == 0.0 and real == 0.0:
@@ -297,31 +300,38 @@ Testing and `doctest` will be covered in a later concept.
297300

298301

299302
```python
300-
# An example on a user-defined function.
303+
# An example on a user-defined function using a Google style docstring.
301304
>>> def raise_to_power(number, power):
302-
"""Raise a number to an arbitrary power.
303-
304-
:param number: int the base number.
305-
:param power: int the power to raise the base number to.
306-
:return: int - number raised to the specified power.
305+
"""Raise a number to an arbitrary power.
306+
307+
Parameters:
308+
number (int): The base number.
309+
power (int): The power to raise the base number to.
310+
311+
Returns:
312+
int: The number raised to the specified power.
313+
314+
Takes a number and raises it to the specified power, returning the result.
307315
308-
Takes a number and raises it to the specified power, returning the result.
309-
"""
316+
"""
310317

311-
return number ** power
318+
return number ** power
312319
...
313320

314321
# Calling the .__doc__ attribute of the function and printing the result.
315322
>>> print(raise_to_power.__doc__)
316323
Raise a number to an arbitrary power.
317324

318-
:param number: int the base number.
319-
:param power: int the power to raise the base number to.
320-
:return: int - number raised to the specified power.
325+
Parameters:
326+
number (int): The base number.
327+
power (int): The power to raise the base number to.
321328

322-
Takes a number and raises it to the specified power, returning the result.
329+
Returns:
330+
int: The number raised to the specified power.
323331

332+
Takes a number and raises it to the specified power, returning the result.
324333

334+
...
325335

326336
# Printing the __doc__ attribute of the built-in type: str.
327337
>>> print(str.__doc__)
@@ -333,10 +343,11 @@ errors is specified, then the object must expose a data buffer
333343
that will be decoded using the given encoding and error handler.
334344
Otherwise, returns the result of object.__str__() (if defined)
335345
or repr(object).
336-
encoding defaults to sys.getdefaultencoding().
346+
encoding defaults to 'utf-8'.
337347
errors defaults to 'strict'.
338348
```
339349

350+
340351
[PEP257]: https://www.python.org/dev/peps/pep-0257/
341352
[calls]: https://docs.python.org/3/reference/expressions.html#calls
342353
[classes]: https://docs.python.org/3/reference/datamodel.html#classes

concepts/basics/introduction.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ A name can be reassigned (or re-bound) to different values (different object typ
2525

2626

2727
```python
28-
>>> my_first_variable = 1 # my_first_variable bound to an integer object of value one.
29-
>>> my_first_variable = 2 # my_first_variable re-assigned to integer value 2.
28+
>>> my_first_variable = 1 # <--my_first_variable bound to an integer object of value one.
29+
>>> my_first_variable = 2 # <--my_first_variable re-assigned to integer value 2.
3030

3131
>>> print(type(my_first_variable))
3232
<class 'int'>
3333

3434
>>> print(my_first_variable)
3535
2
3636

37-
>>> my_first_variable = "Now, I'm a string." # You may re-bind a name to a different object type and value.
37+
>>> my_first_variable = "Now, I'm a string." # <--You may re-bind a name to a different object type and value.
3838
>>> print(type(my_first_variable))
3939
<class 'str'>
4040

41-
>>> my_first_variable = 'You can call me "str".' #<-- Strings can be declared using single or double quote marks.
41+
>>> my_first_variable = 'You can call me "str".' # <--Strings can be declared using single or double quote marks.
4242
>>> print(my_first_variable)
4343
You can call me "str".
4444
```
@@ -60,7 +60,7 @@ Statements for the _body_ of the function begin on the line following `def` and
6060

6161

6262
```python
63-
# The body of this function is indented by 2 spaces,& prints the sum of the numbers.
63+
# The body of this function is indented by 2 spaces & prints the sum of the numbers.
6464
def add_two_numbers(number_one, number_two):
6565
total = number_one + number_two
6666
print(total)
@@ -72,7 +72,7 @@ def add_two_numbers(number_one, number_two):
7272
# Inconsistent indentation in your code blocks will raise an error.
7373
>>> def add_three_numbers_misformatted(number_one, number_two, number_three):
7474
... result = number_one + number_two + number_three # This was indented by 4 spaces.
75-
... print(result) #this was only indented by 3 spaces
75+
... print(result) # <--This was only indented by 3 spaces.
7676
...
7777
...
7878
File "<stdin>", line 3
@@ -104,12 +104,11 @@ def add_two_numbers(number_one, number_two):
104104

105105

106106
Functions that do not have an _explicit_ expression following a `return` will _implicitly_ return the [`None`][none] object.
107-
The details of `None` will be covered in a later exercise.
107+
The details of `None` will be covered in a later concept.
108108
For the purposes of this exercise and explanation, `None` is a placeholder that represents nothing, or null:
109109

110110

111111
```python
112-
113112
# This function will return `None`
114113
def square_a_number(number):
115114
square = number * number
@@ -131,8 +130,7 @@ Functions that omit `return` will also _implicitly_ return the [`None`][none] o
131130
This means that if you do not use `return` in a function, Python will return the `None` object for you.
132131

133132
```python
134-
135-
# This function omits a return keyword altogether
133+
# This function omits a return keyword altogether.
136134
def add_two_numbers(number_one, number_two):
137135
result = number_one + number_two
138136

@@ -158,29 +156,35 @@ Each line of a comment block must start with the `#` character.
158156
## Docstrings
159157

160158
The first statement of a function body can optionally be a [_docstring_][docstring], which concisely summarizes the function or object's purpose.
161-
Docstring conventions are laid out in [PEP257][pep257].
159+
Docstrings are read by automated documentation tools such as [Sphinx][sphinx] and are returned by calling the special attribute `.__doc__` on the function, method, or class name.
160+
General docstring conventions are laid out in [PEP257][pep257], but exact formats will vary by project and team.
162161
Docstrings are declared using triple double quotes (""") indented at the same level as the code block:
163162

164163

165164
```python
166-
167-
# An example from PEP257 of a multi-line docstring.
165+
# An example from PEP257 of a multi-line docstring
166+
# reformatted to use Google style non-type hinted docstrings.
167+
# Some additional details can be found in the Sphinx documentation:
168+
# https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#getting-started
168169
def complex(real=0.0, imag=0.0):
169170
"""Form a complex number.
170171
171-
Keyword arguments:
172-
real -- the real part (default 0.0)
173-
imag -- the imaginary part (default 0.0)
172+
Keyword Arguments:
173+
real (float): The real part of the number (default 0.0)
174+
imag (float): The imaginary part of the number (default 0.0)
175+
174176
"""
175177

176178
if imag == 0.0 and real == 0.0:
177179
return complex_zero
178-
179180
```
180181

181-
[pep257]: https://www.python.org/dev/peps/pep-0257/
182+
Docstrings can also function as [lightweight unit tests][doctests], which will be covered in a later concept.
183+
184+
182185
[comments]: https://realpython.com/python-comments-guide/#python-commenting-basics
183186
[docstring]: https://docs.python.org/3/tutorial/controlflow.html#tut-docstrings
187+
[doctests]: https://docs.python.org/3/library/doctest.html
184188
[duck typing]: https://en.wikipedia.org/wiki/Duck_typing
185189
[dynamic typing in python]: https://stackoverflow.com/questions/11328920/is-python-strongly-typed
186190
[everythings an object]: https://docs.python.org/3/reference/datamodel.html
@@ -190,6 +194,8 @@ def complex(real=0.0, imag=0.0):
190194
[module]: https://docs.python.org/3/tutorial/modules.html
191195
[none]: https://docs.python.org/3/library/constants.html
192196
[parameters]: https://docs.python.org/3/glossary.html#term-parameter
197+
[pep257]: https://www.python.org/dev/peps/pep-0257/
193198
[return]: https://docs.python.org/3/reference/simple_stmts.html#return
194-
[type hints]: https://docs.python.org/3/library/typing.html
195199
[significant indentation]: https://docs.python.org/3/reference/lexical_analysis.html#indentation
200+
[sphinx]: https://www.sphinx-doc.org/en/master/usage/index.html
201+
[type hints]: https://docs.python.org/3/library/typing.html

0 commit comments

Comments
 (0)