![]() ![]() Namespaces are one honking great idea - let 's do more of those! 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. Although never is often better than * right * now. ![]() Although that way may not be obvious at first unless you 're Dutch. There should be one - and preferably only one - obvious way to do it. In the face of ambiguity, refuse the temptation to guess. Special cases aren 't special enough to break the rules. > import this The Zen of Python, by Tim Peters Beautiful is better than ugly. + 10.Ī non-Pythonic solution would be something like this: We have to add the first 10 numbers together like so 1 + 2 +. To write Pythonic code you can't just idiomatically translate another language (like Java or C++) to Python you need to be thinking in Python to being with. There's a big difference between writing Python code and writing Pythonic code. list manipulation (initialization, slicing).It simply means that you're using Python's idioms and paradigms well in order to make your cleaner, readable, and highly performant. Pythonic code is a set of idioms, adopted by the Python community. If you want to learn more read the official PEP 8 reference. multi-line comments used in functions (docstrings) should have a short single-line description followed by more text.comments should have a space after the # sign with the first word capitalized.comments should not contradict the code.don't use spaces around the = sign when used to indicate a keyword argument.if operators with different priorities are used, consider adding whitespace around the operators with the lowest priority.always surround binary operators with a single space on either side.avoid extra spaces within brackets or braces. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |