-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay30.py
More file actions
88 lines (59 loc) · 1.68 KB
/
Day30.py
File metadata and controls
88 lines (59 loc) · 1.68 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Docstrings in Python
# docstrings are the string literals that appear right agter the definition of a fuction,
# method, class, or module
def square(n):
"""Takes in a number n, returns the
square of n"""
print(n ** 2)
square(5)
# To see the docstring.
print(square.__doc__)
# Python Comments vs Docstrings
# Python comments
# They are descriptions that help programmers better understand the intent & functionality of code.
# They are completely ignored by the python interpreter.
# Python docstrings
# As mentioned at the start, Python docstrings are strings used right after the definition of a f(), classs, module.
# we can access these docstrings using the doc attribute.
def my_function():
""" ' 'Demonstrates triple double quotes docstrings and does nothing really' ' """
return None
print("Using __doc__:")
print(my_function.__doc__)
print("Using help:")
help(my_function)
def multiply_numbers(a, b):
"""
Multiplies two numbers and returns the result.
Args:
a (int): The first number.
b (int): The second number.
Returns:
int: The product of a and b.
"""
return a * b
print(multiply_numbers(3, 5))
# Numpydoc Style Docstrings
def divide_numbers(a, b):
"""
Divide two numbers.
Parameters
----------
a : float
The dividend.
b : float
The divisor.
Returns
-------
float
The quotient of the division.
"""
if b == 0:
raise ValueError("Division by zero is not allowed.")
return a / b
print(divide_numbers(3, 6))
# One-line Docstrings
def power(a, b):
""" ' 'Returns arg1 raised to power arg2.' ' """
return a ** b
print(power.__doc__)