You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Docstrings are read by automated documentation tools and are returned by calling the special attribute `.__doc__` on the function, method, or class name.
228
-
Docstring conventions are laid out in [PEP257][pep257].
232
+
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.
233
+
General docstring conventions are laid out in [PEP257][pep257], but exact formats will vary by project and team.
234
+
Exercism concept exercises try to follow the Google style for un-type hinted code.
229
235
230
236
Docstrings can also function as [lightweight unit tests][doctests], which will be covered in a later exercise.
231
237
232
238
233
239
```python
234
240
# An example on a user-defined function.
241
+
# This uses Google style docstrings.
235
242
>>>defraise_to_power(number, power):
236
-
"""Raise a number to an arbitrary power.
237
-
238
-
:param number: int the base number.
239
-
:param power: int the power to raise the base number to.
240
-
:return: int - number raised to the specified power.
243
+
"""Raise a number to an arbitrary power.
244
+
245
+
Parameters:
246
+
number (int): The base number.
247
+
power (int): The power to raise the base number to.
248
+
249
+
Returns:
250
+
int: The number raised to the specified power.
251
+
252
+
Takes a number and raises it to the specified power, returning the result.
241
253
242
-
Takes a number and raises it to the specified power, returning the result.
243
-
"""
254
+
"""
244
255
245
-
return number ** power
256
+
return number ** power
246
257
...
247
258
248
259
# Calling the .__doc__ attribute of the function and printing the result.
249
260
>>>print(raise_to_power.__doc__)
250
261
Raise a number to an arbitrary power.
251
262
252
-
:param number: int the base number.
253
-
:param power: int the power to raise the base number to.
254
-
:return: int- number raised to the specified power.
263
+
Parameters:
264
+
number (int): The base number.
265
+
power (int): The power to raisethe base number to.
255
266
256
-
Takes a number and raises it to the specified power, returning the result.
267
+
Returns:
268
+
int: The number raised to the specified power.
269
+
270
+
Takes a number and raises it to the specified power, returning the result.
0 commit comments