Remember the principle that one function is one purpose. So if it is needed - put some code into a separate method, feel free about it.
Don't use a redundant return
statement if it doesn't do anything.
Good example:
def change_item(self) -> None:
self.length += 2
Bad example:
def change_item(self) -> None:
self.length += 2
return
Also, don't use an empty return
if you have multiple conditions and an
elif
statement can be used.
Good example:
if a == b:
# do something
elif a == c:
# do something
elif a == d:
# do something
Bad example:
if a == b:
# do something
return
if a == c:
# do something
return
if a == d:
# do something
return
Don't use redundant else
if a non-empty return
is used:
Good example:
if a == b:
if a == c:
return "Yes"
return "Maybe"
return "No"
Bad example:
if a == b:
if a == c:
return "Yes"
else:
return "Maybe"
else:
return "No"
Check that all the attributes you define in the __init__
method are used.