![]() ![]() ![]() You may notice that some of these guidelines appear to contradict each other, whereas others may or may not be applicable based on a given scenario.Īlso note that, even though the Zen supposedly contains 20 best practices, there are only 19 in the list. This is why you see the Zen printed to your screen when you import the this module. At the end of this module, there is the print statement: print("".join()) This sequence of commands will enable you to see the location of the zen of python on your local machine and view the contents of the module on the command line.Īs mentioned above, the zen of python is just stored as a string object in the this.py module. If you're curious and want to peek under the hood, you can view the actual contents of the this.py file as follows: $ python3 Namespaces are one honking great idea - let's do more of those!įrom a technical perspective, the Zen of Python is actually just a multiline string that is stored in a module called "this.py", which is installed along with other Python builtin modules within your Python installation. If the implementation is easy to explain, it may be a good idea. If the implementation is hard to explain, it's a bad idea. ![]() There should be one- and preferably only one -obvious way to do it.Īlthough that way may not be obvious at first unless you're Dutch.Īlthough never is often better than *right* now. In the face of ambiguity, refuse the temptation to guess. Special cases aren't special enough to break the rules. Thanks to his contribution, anyone can view the Zen straight from the Python interpreter by running import this, which you can think of as the Zen of Python command: > import this How to Print the Zen of Python?īarry Warsaw added the Zen of Python into the Python language as an easter egg back in 2001. In this article, you'll take a look at the different rules of thumb posited by the Zen of Python, as well as how to implement them in your development workflow. It's become a well-known standard for writing clean and elegant Python code, so much so that it was standardized as PEP 20 in 2004. Some might say he helped define zen, at least with regards to Python programming.įor years, Python programmers have used the Zen to scaffold their own development process. The Zen of Python is a list of 20 rules of thumb for writing Pythonic code - that is, code that exhibits the design philosophy that the creators had in mind when developing the language.ġ9 of these rules were submitted to a Python Usenet group back in the late 1990s by none other than Tim Peters, one of Python's core developers. Programming is no different, and for Pythonistas, these best practices are codified into what's known as the Zen of Python. You can easily explain your code to non-technical peersĮvery industry has its "best practices" - a set of guidelines for both newcomers and veterans to follow in order to maximize their contribution to the field.You’re shipping (clean code) to production.Your code follows best practices where necessary.Your code is appropriate for the use case in question. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |