In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about the colored eggs in Python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
1. Hello World
Legend has it that in ancient times there was a retired programmer who had nothing to do at home and decided to practice calligraphy. On the first day, he prepared pen, ink, paper and inkstone, and wrote down a line of big words: "hello, world". Hello world is the beginning for programmers to learn a new programming language, and Python simply embeds it in the built-in module.
> > import _ _ hello__Hello World...
When it comes to python3, the output will be slightly changed. Replaced by!
> > import _ hello__Hello World! 2. The Zen of Python
Hidden in import this is a poem called "Zen of Python", which is the "eight Honors and eight disgraces" in Python. The author is Tim Peters, which should be kept in mind by every aspiring Python programmer.
> > import thisThe Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Although practicality beats purity.Errors should never pass silently.Unless explicitly silenced.In the face of ambiguity Refuse the temptation to guess.There should be one-- and preferably only one-- obvious way to do it.Although that way may not be obvious at first unless you're Dutch.Now is better than never.Although never is often better than * right* now.If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea-let's do more of those!
Reference translation:
Beautiful is better than ugly. Beauty is better than ugliness. Explicit is better than implicit. Explicit is better than implicit. Simple is better than complex. Simplicity is better than complexity. Complex is better than complicated. Complexity is better than difficulty. Flat is better than nested. Flatness is better than nesting. Sparse is better than dense. Dispersion is better than density. Readability counts. Readability should be valued. Special cases aren't special enough to break the rules. Although practicality beats purity. Although practicality beats purity, exceptions are not above the rules. Errors should never pass silently. Unless explicitly silenced. Mistakes should never slip away in silence unless they are explicitly silenced. In the face of ambiguity, refuse the temptation to guess. In the face of unclear definition, reject the temptation to guess. There should be one- and preferably only one- obvious way to do it. In one way, there is only one way to do one thing. Although that way way not be obvious at first unless you're Dutch. Although this approach may not be obvious at first, you are not the father of Python. Now is better than never. Although never is often better than right now. It is better to do it than not to do it, but sometimes it is better to do it right away than not to do it at all. If the implementation is hard to explain, it's a bad idea. If implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea-let's do more of those! Namespaces are a great idea, so let's use them more! 3. Antigravity
Import antigravity is a funny color egg, it jumps directly to a comic book page http://xkcd.com/353/, the cartoon is very interesting, Cueball floats in the sky, a friend asks him curiously how to fly.
The dialogue in this picture is:
Friend: wow! You're flying. How did you do that?
Cueball:Python!
Cueball: I learned it last night. It's very simple.
Cueball: it only takes one sentence to run Hello World: print "Hello World!"
Friend: I don't know anything about dynamic types, white space characters and so on.
Cueball: come and join us! Python programming is fun. It's a whole new world.
Friend: but how did you fly?
Cueball: I just typed in import antigravity
Friend: that's it? (or an unperplexed expression)
Cueball: … Well, I also compared everything in the medicine cabinet (implying that Cueball has compared many programming languages, but still thinks Python is the simplest)
Cueball: but I think this is Python
4. Braces replace indentation
The biggest grammatical difference between Python and other languages is the way code blocks end. Python code blocks are much simpler, and a C-like syntax:
If (x > y) {x = 1; y = 2;}
The equivalent statement in Python:
If x > y: X = 1 y = 2
One of the goals of Python is to get programmers to type less and make life more fun. Instead of typing begin/end, then/endif, or {} like a C-like language to end the code block, Python uses indentation to end the code block. The braces library is the most ridiculous egg in Python. If you are a programmer from a C-like language, you probably won't be able to adapt to the indentation of Python by 01:30, is there any other way? The braces module is a compatibility solution designed specifically for C programmers.
> from _ future__ import braces File "", line 1SyntaxError: not a chance
Haha, I was deceived into thinking that you can use curly braces to end the code block by importing braces. The answer Python tells you is: no way!
5. HTTPServer
If you want your colleagues to temporarily access the file directory on your computer, the usual practice is to set up a shared directory for everyone to access, but if you install Python, everything becomes much easier, just open a command line window, change to the specified directory, and execute:
Python-m SimpleHTTPServer # python2python-m http.server # python3
This is a simple http server built into Python to make it easy for yourself and others to use browsers to access your file directory.
These are all the contents of the article "what are the eggs in Python?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.