File tree 1 file changed +24
-0
lines changed
Writing Functions in Python
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -32,3 +32,27 @@ def func_name(arguments):
32
32
import inspect
33
33
print(inspect.getdoc(func_name))
34
34
**************************************************************************************************************************************************************"""
35
+ ## Crafting a docstring
36
+
37
+ # Add a docstring to count_letter()
38
+ def count_letter (content , letter ):
39
+ """Count the number of times `letter` appears in `content`.
40
+
41
+ # Add a Google style arguments section
42
+ Args:
43
+ content (str): The string to search.
44
+ letter (str): The letter to search for.
45
+
46
+ # Add a returns section
47
+ Returns:
48
+ int
49
+
50
+ # Add a section detailing what errors might be raised
51
+ Raises:
52
+ ValuError: If `letter` is not a one-character string
53
+ """
54
+ if (not isinstance (letter , str )) or len (letter ) != 1 :
55
+ raise ValueError ('`letter` must be a single character string.' )
56
+ return len ([char for char in content if char == letter ])
57
+
58
+
You can’t perform that action at this time.
0 commit comments