Posts

Showing posts with the label Syntax

Good and bad practices while programming using python

Image
Python is a high-level multi-paradigm programming language that emphasizes readability. It’s being developed, maintained, and often used following the rules called The Zen of Python or PEP 20. This article shows several examples of good and bad practices of coding in Python that you’re likely to meet often. Using Unpacking to Write Concise Code Packing and unpacking are powerful Python features. You can use unpacking to assign values to your variables: >>> a , b = 2 , 'my-string' >>> a 2 >>> b 'my-string' You can exploit this behavior to implement probably the most concise and elegant variables swap in the entire world of computer programming: >>> a , b = b , a >>> a 'my-string' >>> b 2 That’s awesome! Unpacking can be used for the assignment to multiple variables in more complex cases. For example, you can assign like this: >>> x