Python Black Hat programming 2.1 Python programming philosophy

Source: Internet
Author: User

Python Black Hat programming 2.1 Python programming philosophy

The content of this section is interesting and involves why many people choose Python and why they like the language. I take you to the Python author's Zen of Python, and then learn about Python's programming specifications.

2.1.1 ZEND of PYTHON

Start the terminal in Kali, enter Python, and enter interactive mode.

Figure 2

Input command

Import This

"A poem" appears before our eyes.

Figure 3

The contents are as follows:

Beautiful is better than ugly. beauty is better than uglinessExplicit is better than implicit. clarity is better than obscuritySimple is better than complex. simpler than complexComplex is better than complicated.complexity is better than clutterFlat is better than nested. flat is better than nestingSparse is better than dense. spacing is better than compactnessreadability counts. Readability is importantSpecial cases aren ' t special enough to break the rules. even in the name of the practicality of the special case, it does not violate these rules.Although practicality beats purity. Although practicality is more than purityErrors should never pass silently. errors should not be silently ignoredunless explicitly silenced. unless the clear silencein the face of ambiguity, refuse the temptation to guess.when there are many possibilities, don't try to guessthere should is one--and preferably only one--obvious the-do it.there should be one, preferably only one, obviously able to do thisAlthough that is obvious at first unless you ' re Dutch.Although this may not be easy, unless you are the father of PythonNow is better than never. It's better than not doing it now.Although never is often better than *right* now.Although the past is never better than the presentIf The implementation is hard to explain, it's a bad idea.If this implementation is not easy to explain, then it must be a bad idea.If The implementation is easy to explain, it could be a good idea. If this implementation is easy to explain, then it's probably a good idea .namespaces is one honking great idea – let's do more than those!namespaces are a wonderful idea and should be used more

I don't have much to explain about this biblical description, and with the richness of programming experience, understanding will be more and more profound. Now, you just have to read it silently and put it in your own collection.

2.1.2 Coding Specification

The following content is important, it is recommended that beginners as a golden rule to abide by.

For starters, I have to emphasize that Python does not have curly braces like the C language, can represent the hierarchical relationship between code blocks and code, and does not have VB-like begin...end, which are represented by indentation. For the curly braces of the programmer, it is somewhat uncomfortable, because there are curly braces, we can arbitrarily adjust the indentation, let the code in accordance with our aesthetic, but in Python cannot do so. Look at the following short example:

stringstest = ' Abcdefghijk ' For Char in stringstest[1:]:if char! = ' C ':print ' not C '

This code is very simple, first declares a string variable stringstest, and then iterates through the characters in the string, judging whether the letter "C", if not print "not C". After running, you will see the following error:

Figure 4

For simple analysis, the for loop and variable declarations are in the same class, and they are currently the top level of the test code and do not need to be indented. The IF condition is judged to be a subset of the for, there should be a 4-space indent, the print statement is a subset of if, and the if reference should be indented with 4 spaces. The modified code is as follows:

Figure 5

Run result 6.

Figure 6below I put PEP8 Python coding specification quoted come over, translation is not my original, from http://damnever.github.io/2015/04/24/ pep8-style-guide-for-python-code/, thank Damnever hard pay, please click the link to read the original.

Section 2.2, "Data type" has been in the first release of the subscription number, impatient students into the subscription number (QR code below), from the menu "network Security", "Python Black Hat Programming" to enter.

Since the tutorial is still in the process of authoring, before the end of the complete tutorial, interested students please follow my subscription number (xuanhun521, the QR code below), I will be the first time in the subscription number to push the text tutorial and video tutorial.

Python Black Hat programming 2.1 Python programming philosophy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.