Python is a beautiful programming language. It contains really useful features that make writing code more efficient than ever.
Here are 5 tips for writing more efficient and compact code.
https://abs.twimg.com/emoji/v2/... draggable="false" alt="🧵" title="Thread" aria-label="Emoji: Thread">
https://abs.twimg.com/emoji/v2/... draggable="false" alt="🧵" title="Thread" aria-label="Emoji: Thread">
https://abs.twimg.com/emoji/v2/... draggable="false" alt="🧵" title="Thread" aria-label="Emoji: Thread">
Here are 5 tips for writing more efficient and compact code.
1. Decorator
A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure.
https://book.pythontips.com/en/latest/decorators.html">https://book.pythontips.com/en/latest...
A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure.
https://book.pythontips.com/en/latest/decorators.html">https://book.pythontips.com/en/latest...
2. Generator
A generator is a special type of function which does not return a single value, instead, it returns an iterator object with a sequence of values.
https://www.tutorialsteacher.com/python/python-generator">https://www.tutorialsteacher.com/python/py...
A generator is a special type of function which does not return a single value, instead, it returns an iterator object with a sequence of values.
https://www.tutorialsteacher.com/python/python-generator">https://www.tutorialsteacher.com/python/py...
3. Ternary operator (condition)
A Ternary operator allows you to quickly test a condition instead of a multiline if statement.
https://book.pythontips.com/en/latest/ternary_operators.html">https://book.pythontips.com/en/latest...
A Ternary operator allows you to quickly test a condition instead of a multiline if statement.
https://book.pythontips.com/en/latest/ternary_operators.html">https://book.pythontips.com/en/latest...
4. Enumerate
Enumerate adds a counter to an iterable and returns it in a form of an enumerate object.
https://www.geeksforgeeks.org/enumerate-in-python/">https://www.geeksforgeeks.org/enumerate...
Enumerate adds a counter to an iterable and returns it in a form of an enumerate object.
https://www.geeksforgeeks.org/enumerate-in-python/">https://www.geeksforgeeks.org/enumerate...
5. setattr & getattr
The setattr function sets the value of the specified attribute of the specified object. The getattr method returns the value of the named attribute of an object.
The setattr function sets the value of the specified attribute of the specified object. The getattr method returns the value of the named attribute of an object.
Let me know what functions or features you find useful and are worth sharing!