11 Tips And Tricks To Write Better Python Code

Published: 05 July 2020
on channel: Patrick Loeber
614,483
25k

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.

Find Python jobs: https://pythonengineer.pallet.com

~~~~~~~~~~~~~~ GREAT PLUGINS FOR YOUR CODE EDITOR ~~~~~~~~~~~~~~
✅ Write cleaner code with Sourcery: https://sourcery.ai/?utm_source=youtu... *

📚 Get my FREE NumPy Handbook:
https://www.python-engineer.com/numpy...

📓 Notebooks available on Patreon:
  / patrickloeber  

⭐ Join Our Discord :   / discord  

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:    • List Comprehension in Python - A Pyth...  

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

🖥️ Website: https://www.python-engineer.com
🐦 Twitter -   / patloeber  
✉️ Newsletter - https://www.python-engineer.com/newsl...
📸 Instagram -   / patloeber  
🦾 Discord:   / discord  
▶️ Subscribe:    / @patloeber  

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

🅿 Patreon -   / 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! 🙏


On this page of the site you can watch the video online 11 Tips And Tricks To Write Better Python Code with a duration of hours minute second in good quality, which was uploaded by the user Patrick Loeber 05 July 2020, share the link with friends and acquaintances, this video has already been watched 614,483 times on youtube and it was liked by 25 thousand viewers. Enjoy your viewing!