Python 3 Best Practices

To kick things off: best practices. These are the rules that will make your code look like a pro’s and help you avoid any embarrassing errors or bugs. Here are our top picks for Python 3 best practices:
1️ Use whitespace to your advantage! Don’t be afraid of those tabs, They can really help you organize your code and make it easier to read. Just remember to use four spaces instead of a tab (unless you’re working on an old-school project that still uses tabs).
2️ Use docstrings! These are like little notes for your code, explaining what each function or module does and how it works. They can be super helpful when someone else is trying to understand your code (or if you’re trying to remember what the ***** that line of code was supposed to do).
3️ Use type hints! These are like little notes for your variables, explaining what kind of data they should contain. They can be super helpful when someone else is trying to understand your code (or if you’re trying to remember what the ***** that variable was supposed to hold).
4️ Use functions! These are like little tools for your code, doing specific tasks and making it easier to read. They can be super helpful when someone else is trying to understand your code (or if you’re trying to remember what the ***** that function was supposed to do).
5️ Use comments! These are like little notes for yourself, explaining why you did something or how it works. They can be super helpful when someone else is trying to understand your code (or if you’re trying to remember what the ***** that line of code was supposed to do).
Now, some best practices for writing comments in Python specifically:
– Keep them short and sweet. No one wants to read a novel when they could just look at your code.
– Use comments sparingly. If you have to explain why something is there, maybe it needs to be rewritten or removed altogether.
– Avoid using comments as an excuse for bad coding practices (like not following PEP 8). Comments should enhance the readability of your code, not cover up its flaws.
– Use inline comments sparingly and only when necessary. If you have a long explanation to give, use docstrings instead.
– Don’t forget to update your comments as your code changes! Outdated comments can be worse than no comments at all.
And there you have it, Our top picks for Python 3 best practices and tips for writing cleaner comments.

SICORPS