In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to understand Python from the mystery of Hello World to the Zen of Python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to understand the mystery of Python from the mystery of Hello World to the Zen of Python.
1. The simplest "HelloWorld"
What was the first line of code you wrote? A thousand Hamlets may all have the same answer-"HelloWorld". So, did it ever occur to you that print (Hello World!) is not the only way to type these two words?
In fact, you can implement HelloWorld simply by importing modules hidden by Python developers. Try this:
> > import _ hello__ Hello World!
This code is only 16 characters, including the spacebar! This is one of the "simplest" HelloWorld programs. Note that you cannot reimport the module in the Python program, so you can print the information once each time you run it.
2. The Zen of Python
This is a concept proposed in PEP20. PEP refers to the enhanced proposal for Python.
Is Python your favorite language? What do you like about it? Is it a design? There are 20 guidelines that describe Python design, 19 of which can be found in the following ways:
> import this
Where's the other one? The author guesses that people cannot know everything. Here are the first three guiding principles:
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex.
We must thank the developers for their efforts in making such an elegant and easy-to-read programming language. This is the only "official" program called "colored egg" in the Python developer's guide so far.
3. Experience anti-gravity cartoons
One line of Python code, you can experience anti-gravity comics!
Import antigravity
Just try it! Keep in mind that by doing so, you may be trapped in outer space and browse xkcd comics for hours.
4. Parenthesis
Unlike many other programming languages, Python does not actually use curly braces {} when constructing statements, functions, and loops, but it may be used later.
The _ _ future__ module contains incompatible changes that will be enforced in the near future. For example, importing print_function from _ _ future__ in Python2.6 or 2.7allows "print" to become a function that accepts the parameter print (), just as in Python 3.
See how parentheses work starting with _ _ future__:
> from _ _ future__ importbraces SyntaxError: not a chance
5. This.py
Remember the first three lines of the Python Zen?
After digging deeper and finding the module file this.py, you will find that this is by far the prettiest, clearest, and simplest code.
6. Hash
The hash of infinity and NaN.
> hash (float (inf)) 314159 > hash (float (nan)) 0
This colored egg was found on Reddit. The author really wants to know the ultimate answer to life, the universe and everything. (source: a Guide to the Galaxy.)
7. Uncle Barry.
The debate about operator selection has been going on for 42 years. It's time to solve it!
This question was raised in PEP 401, and the following is not hard to guess. The famous Python developer Barry Warsaw (also known as Uncle Barry) has been "selected" to become a lifelong friendly language uncle, or FLUFL for short.
He made some "modifications", replacing the inequality operator with the diamond operator! =. If you agree with Uncle Barry, you can import this interesting library, and the syntax will take effect, and! = will lead to syntax errors.
> from _ future__ importbarry_as_FLUFL > 0! = 1 SyntaxError: with Barry as BDFL, use instead of! > > 0 1 True > 1 1 False so far, I believe you have a deeper understanding of "how to understand the mystery of Python from the mystery of Hello World to the Zen of Python". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.