def string_to_lower(s :: str) -> str:
return s.lower()
since you could always use s.lower()
instead.Write docstrings for all functions, including helper and nested functions.
A good docstring gives a description of the function, including its input(s) and output. Ideally, by looking at the docstring you know what the function does and how to use it without looking at the function body itself.
Give constants and helper functions useful names.
All functions require type annotations on inputs and output. You can omit output annotation for functions that have no return (for example functions that only need to print
).
Names of constants and functions should be lower case and underscore separated. For configuration constants (for example the height of a character) it is acceptable to use all caps names.
Keep lines under 120 characters.
Indent your code properly. If you are using Pycharm, this should be happening automatically. If you are not using Pycharm, use 4 spaces to indent your code (not the tab character) and keep arguments of functions lined up:
def func_name(long_parameter_1 : int, long_parameter_2 : str
long_parameter_3 : list, long_parameter_4 : list) -> int:
...
func_name(long_argument_1, long_argument_2,
long_argument_3, long_argument_4)
return
statements should be not be written like this:return(value)
but rather like this:
return value
if
statements should be written with newlines:if condition1:
print('condition1')
elif condition2:
print('condition2')
else:
print('condition3')