In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Python (British pronunciation: / pa θ n / American pronunciation: / pa θ pronunciation /) is an object-oriented interpretive computer programming language invented by the Dutch Guido van Rossum in 1989. The first public distribution version was released in 1991.
Python is pure free software, and the source code and interpreter CPython follow the GPL (GNU General Public License) protocol.
Python syntax is concise and clear, one of the features is to force the use of blank characters (white space) as statement indentation.
Python has a rich and powerful library. It is often nicknamed glue language and can easily connect various modules made in other languages (especially CpicurCraft +). A common application scenario is to use Python to quickly generate a prototype of the program (sometimes even the final interface of the program), and then rewrite the parts with special requirements in a more appropriate language, such as the graphics rendering module in 3D games. If the performance requirements are particularly high, it can be rewritten with C _ Python +, and then encapsulated into an extension library that can be called by Python. It is important to note that you may need to consider platform issues when using extended class libraries, and some may not provide cross-platform implementations.
style
Python adheres to a clear and uniform style in design, which makes Python a widely used language that is easy to read, easy to maintain, and welcomed by a large number of users.
The overall guiding idea for designers to develop is that for a particular problem, as long as there is the best way to solve it. This is expressed in the Python motto (called The Zen of Python) written by Tim Peters as: There should be one-- and preferably only one-- obvious way to do it. This is exactly the opposite of TMTOWTDI (There's More Than One Way To Do It), the central idea of the Perl language, another high-level dynamic language with similar functions.
The authors of Python deliberately designed restrictive syntax so that bad programming habits (such as not indenting the next line of an if statement to the right) could not be compiled. One of the most important of these is the indentation rules of Python.
One difference from most other languages (such as C) is that the boundary of a module is entirely determined by the position of the first character of each line on that line (while C uses a pair of curly braces {} to clearly define the boundary of the module, it has nothing to do with the position of the characters). This has been controversial in the past. Because since the birth of languages such as C, the grammatical meaning of the language has been separated from the arrangement of characters, which has been regarded as an improvement in programming languages. However, there is no denying that Python does make the program clearer and more beautiful by forcing programmers to indent (including if,for and function definitions where modules are needed).
design position
Python's design philosophy is "elegant", "clear" and "simple". As a result, the idea that there are always multiple ways to do the same thing in the Perl language is often unbearable among Python developers. The philosophy of Python developers is "one way, preferably only one way to do one thing." When designing a Python language, if faced with multiple choices, Python developers will generally reject fancy syntax and choose explicit syntax with little or no ambiguity. Because of this difference in design concepts, Python source code is generally considered to be more readable than Perl and can support large-scale software development. These principles are called Python maxims. Run import this within the Python interpreter to get a complete list.
Python developers try to avoid immature or unimportant optimizations. Some faster patches for non-critical parts are usually not incorporated into Python. So many people think Python is slow. However, according to the 28 law, most programs do not require high speed. In some cases where running speed is very high, Python designers tend to use JIT technology, or rewrite this part of the program using the Cpicard + language. The available JIT technology is PyPy.
Python is a completely object-oriented language. Functions, modules, numbers, and strings are all objects. And fully support inheritance, overloading, derivation, multi-inheritance, which is beneficial to enhance the reusability of the source code. Python supports overloaded operators and dynamic types. Compared with Lisp, a traditional functional programming language, Python only provides limited support for functional design. Two standard libraries (functools, itertools) provide time-tested functional programming tools in Haskell and Standard ML.
Although Python may be roughly classified as a "scripting language" (script language), it is also widely used by large-scale software development programs such as Zope, Mnet, and BitTorrent,Google. Proponents of Python prefer to call it a high-level dynamic programming language because "scripting language" generally refers to languages that only do simple programming tasks, such as shellscript, VBScript and other programming languages that can only handle simple tasks, not on a par with Python.
Python itself is designed to be extensible. Not all features and functions are integrated into the language core. Python provides a wealth of API and tools, so that programmers can easily use C language, C++, Cython to write extension modules. The Python compiler itself can also be integrated into other programs that require scripting languages. As a result, many people also use Python as a "glue language" (glue language). Use Python to integrate and package programs written in other languages. Many projects within Google, such as Google Engine, use C++ to write the most demanding parts, and then use Python or Java/Go to call the corresponding module. Alex Martelli, author of the Python Technical Manual, said: "it's hard to say, but in 2004, Python was already used internally in Google, and Google recruited a lot of Python masters, but they decided to use Python before that. Their goal was Python where we can, C++ where we must, using Craft for hardware manipulation, and Python for rapid development."
Basic grammar
One of the design goals of Python is to make the code highly readable. It is designed to use punctuation marks and English words that are often used in other languages to make the code look clean and beautiful. It does not need to rewrite declaration statements like other static languages such as C and Pascal, nor does it often have special cases and surprises like their syntax.
Indent
Python developers deliberately force programmers to develop good programming habits by preventing programs that violate indentation rules from being compiled. And the Python language uses indentation to indicate the beginning and exit of a block of statements (Off-side rules) instead of using curly braces or certain keywords. Increasing indentation indicates the beginning of a statement block, while decreasing indentation indicates the exit of a statement block. Indentation becomes part of the grammar. For example, the if statement:
1 2 3 4if age >, > sum (x * x for x in range (10))
two hundred and eighty five
Python uses lambda to represent anonymous functions. The anonymous function body can only be an expression. For example:
> add=lambda x, y: X + y
> add (3)
five
Python uses y if cond else x to represent conditional expressions. It means that when cond is true, the value of the expression is y, otherwise it is x. The equivalent of cond?y:x in C++ and Java.
Python distinguishes lists (list) and tuples (tuple). The way list is written is [1magin 2pr 3], while the way tuple is written is (1pm 2p3). You can change the elements in the list, not the tuple. In some cases, the parentheses of tuple can be omitted. Tuple has special handling for assignment statements. Therefore, you can assign values to multiple variables at the same time, such as:
> XBM y = 1. XBI also assigns a value to XBI y. The final result: Xray 1, YQ 2.
In particular, you can use the following form to exchange the values of two variables:
> x, yellowy, x # final result: yellow1, xroom2
Python uses'(single quotation marks) and "(double quotation marks) to represent strings. Unlike Perl, Unix Shell, or Ruby, Groovy and other languages, the two symbols serve the same purpose. In general, if double quotes appear in a string, single quotation marks are used to represent the string; otherwise, double quotation marks are used. If none of them show up, choose according to your personal preference. The\ (backslash) that appears in the string is interpreted as a special character, such as\ n represents a newline character. The r before the expression indicates that Python does not interpret the\ that appears in the string. This type of writing is often used to write regular expressions or Windows file paths.
Python supports list cutting (list slices), which allows you to get a portion of the complete list. The types that support cutting operations are str, bytes, list, tuple and so on. Its syntax is... [left:right] or... [left:right:stride]. Assuming that the value of the nums variable is [1, 3, 5, 7, 8, 13, 20], the following statements are true:
Nums [2:5] = = [5,7,8] cuts from elements with subscript 2 to elements with subscript 5, but does not include elements with subscript 5.
Nums [1:] = = [3, 5, 7, 8, 13, 20] cut to the last element.
Nums [:-3] = [1, 3, 5, 7] cuts from the original element to the penultimate element.
Nums [:] = [1, 3, 5, 7, 8, 13, 20] returns all elements. Changing the new list will not affect nums.
Nums [1:5:2] = = [3,7] cuts from the element with subscript 1 to the element with subscript 5 but does not contain the element with subscript 5, and the step size is 2.
Would like to know more about:
Http://minglisoft.cn/technology
If friends need, please add a ball: 2042849237
Share more technical knowledge about Python in detail. Thank 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.