In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the reasons for using Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Python reads like executable pseudo code
Pseudocode is a concept that does not follow the exact syntax and syntax of a particular language to write programming logic. Since I became a Python programmer, I have rarely written pseudocode because its actual design meets my needs.
Even if you don't know much about the Python language, you can read it easily, which is largely determined by design.
Python is famous for the white space rule in the code format. White space is necessary for any language-it allows us to distinguish between different words in a sentence. Most languages have suggestions or "good practices" for the use of spaces, but Python boldly requires standardization. For me, this makes it very easy to read the code and see exactly what it is doing.
For example, the following is an implementation of a classic bubble sorting algorithm.
Def bubble_sort (things): needs_pass = True while needs_pass: needs_pass = False for idx in range (1, len (things)): if things [idx-1] > things [idx]: things [idx-1], things [idx] = things [idx], things [idx-1] needs_pass = True
Now let's compare it with the implementation in Java.
Public static int [] bubblesort (int [] numbers) {boolean swapped = true; for (int I = numbers.length-1; I > 0 & & swapped; I muri -) {swapped = false; for (int j = 0; j)
< i; j++) { if (numbers[j] >Numbers [juni1]) {int temp = numbers [j]; numbers [j] = numbers [juni1]; numbers [juni1] = temp; swapped = true;} return numbers;}
I know that Python needs to be indented to represent the nesting of blocks. Although our Java example also makes good use of indentation, it is not necessary. Curly braces determine the start and end of the block, not the interval. Because Python uses spaces as syntax, you don't need the start {and end} symbols in other code.
Python also avoids the need for semicolons, which are syntax rules that make other languages readable. I feel more comfortable reading Python, which is a lot like pseudocode and sometimes makes me surprised that I don't even realize what runnable code looks like!
2. Python has a powerful primitive function
In programming language design, the original function is the simplest available element. The fact that Python is easy to read does not mean that it is a powerful language, on the other hand, it is due to its use of the original function. My favorite example of making Python both easy to use and advanced is its generator concept.
Suppose you have a simple binary tree structure that contains value, left, and right. You want to iterate over it easily in order. You usually look for "small" elements so that you can exit as soon as you find the correct value. So far, it sounds simple. However, there are many algorithms that can manipulate elements.
Other languages will let you write a visitor so that you can tell in this function, "is this the right element?" You can do this in Python, but you don't have to do it either.
Def in_order (tree): if tree is None: return yield from in_order (tree.left) yield tree.value yield from in_order (tree.right)
This generator function will return an iterator that, if used in the for loop, will execute only what is needed, not all. This is very powerful.
3.Python standard library
Python has a great standard library that hides a lot of valuable content that I didn't know before, and I didn't get a general idea until I took the time to traverse the list of all available functions, constants, types, and so on. Personally, I prefer itertools modules, but I prefer functional programming modules (yes, Python supports functional programming!).
It's fun to make fun of your technical interviewer. For example, here's a little trick to deal with the classic interview question of FizzBuzz:
After searching the web, you will find that this is not the most direct way to solve FizzBuzz, but it is really interesting!
In addition to fun, the itertools module as well as the heapq and functools modules are valuable things that are provided by default in the Python implementation.
4. Python's ecosystem is huge.
For many things that are not available in the standard library, there is a huge ecosystem to support the new Pythonista, from exciting packages to language-specific text editor plug-ins. There are about 200000 projects hosted on PyPi (as of this writing), and the number of projects is growing, and everyone can use these tools: data science, asynchronous framework, web framework, or just some tools to make remote automation easier.
This is the end of the content of "what are the reasons for using Python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.