11 Tips And Tricks To Write Better Python Code

In this video, I show 11 Tips and Tricks to Write Better Python code! I show a lot of best practices that improve your code by making your code much cleaner and more Pythonic.

~~~~~~~~~~~~~~ GREAT PLUGINS FOR YOUR CODE EDITOR ~~~~~~~~~~~~~~
πŸͺ Code faster with Kite: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=pythonengineer&utm_content=description-only *
βœ… Write cleaner code with Sourcery: https://sourcery.ai/?utm_source=youtube&utm_campaign=pythonengineer *

πŸ“š Get my FREE NumPy Handbook:

πŸ““ Notebooks available on Patreon:

⭐ Join Our Discord : https://discord.gg/FHMg9tKFSN

If you enjoyed this video, please subscribe to the channel!

All Tips:
1) Iterate with enumerate instead or range(len(x))
2) Use list comprehension instead of raw for loops
3) Sort complex iterables with sorted()
4) Store unique values with Sets
5) Save memory with Generators
6) Define default values in Dictionaries with .get() and .setdefault()
7) Count hashable objects with collections.Counter
8) Format strings with f-Strings (Python 3.6+)
9) Concatenate strings with .join()
10) Merge dictionaries with {**d1, **d2} (Python 3.5+)
11) Simplify if-statements with if x in list

List comprehension Tutorial: https://youtu.be/RaIu2-NM0t0

~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

πŸ–₯️ Website: https://www.python-engineer.com
🐦 Twitter – https://twitter.com/python_engineer
βœ‰οΈ Newsletter – https://www.python-engineer.com/newsletter
πŸ“Έ Instagram – https://www.instagram.com/patloeber
🦾 Discord: https://discord.gg/FHMg9tKFSN
▢️ Subscribe: https://www.youtube.com/channel/UCbXgNpp0jedKWcQiULLbDTA?sub_confirmation=1

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

πŸ…Ώ Patreon – https://www.patreon.com/patrickloeber

Music: https://www.bensound.com/

# Python #Tips

* This is a sponsored or an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! πŸ™

Source of this Python/AI Video

AI video(s) you might be interested in …