def squares_a_list(numerical_list):
new_squared_list = list()
for number in numerical_list:
new_squared_list.append(number ** 2)
return new_squared_listThe NumPy format includes 4 main sections:
def squares_a_list(numerical_list):
"""
Squared every element in a list.
Parameters
----------
numerical_list : list
The list from which to calculate squared values
Returns
-------
list
A new list containing the squared value of each of the elements from the input list
Examples
--------
>>> squares_a_list([1, 2, 3, 4])
[1, 4, 9, 16]
"""
new_squared_list = list()
for number in numerical_list:
new_squared_list.append(number ** 2)
return new_squared_listdef function_name(param1, param2):
"""The first line is a short description of the function.
A paragraph describing in a bit more detail what the function
does and what algorithms it uses and common use cases.
Parameters
----------
param1 : datatype
A description of param1.
param2 : datatype
A longer description because maybe this requires
more explanation, and we can use several lines.
Returns
-------
datatype
A description of the output, data types, and behaviors.
Describe special cases and anything the user needs to know
to use the function.
Examples
--------
>>> function_name(3, 8, -5)
2.0
"""def exponent_a_list(numerical_list, exponent=2):
"""
Creates a new list containing specified exponential values of the input list.
Parameters
----------
numerical_list : list
The list from which to calculate exponential values from
exponent: int or float, optional
The exponent value (the default is 2, which implies the square).
Returns
-------
new_exponent_list : list
A new list containing the exponential value specified of each
of the elements from the input list
Examples
--------
>>> exponent_a_list([1, 2, 3, 4])
[1, 4, 9, 16]
"""
new_exponent_list = list()
for number in numerical_list:
new_exponent_list.append(number ** exponent)
return new_exponent_listFor example, if we want the docstring for the function len():
Signature: len(obj, /)
Docstring: Return the number of items in a container.
Type: builtin_function_or_method
Signature: squares_a_list(numerical_list)
Docstring:
Squared every element in a list.
Parameters
----------
numerical_list : list
The list from which to calculate squared values
Returns
-------
list
A new list containing the squared value of each of the elements from the input list
Examples
--------
>>> squares_a_list([1, 2, 3, 4])
[1, 4, 9, 16]
File: ~/<ipython-input-1-7e6e50ac7556>
Type: function