Python Guide - Appetizer

zhaozj2021-02-11  204

?

Appetizer

If you have written a large-scale shell script, you should have this experience: you still want to add some other functions, but it is too big, too slow, too complicated; or this function needs to call a system Function, or it is only suitable to call through C ... Usually these problems are not enough to seriously write this shell; probable, this feature requires some similar bell strings or other data that is easy to find in the shell script Type (such as an ordered list of filenames), but they use C to achieve a lot of work, or you are not very familiar with C.

Another case: You may need to use a few C libraries to work, usually the write / compilation / test / compilation cycle is too slow. You need to develop software as soon as possible. Maybe you need to write a program that uses the extension language, but don't want to design a language and write a debugging an interpreter for this, then integrate it into your program.

In the case of the above situation, Python may be the language you are looking for. Python is easy to get started, but it is a real programming language that provides a larger structure than a shell, supports large programs. On the other hand, it provides a more error check than C, and as a high-level language, it has built-in advanced data types, such as variable groups and dictionaries, if implemented by C, these work may make You have a big time for a few days. Because there is more general data types, Python is suitable than awk and even Perl, in other fields, Python is more easier than other languages.

Python allows you to divide your program into different modules so that you can reuse in other Python programs. This allows yourself to learn Python program based on a large standard module set or use them as an example. There are some similar file I / O, system calls, sockets, and even user graphics interfaces like TK.

Python is an interpreted language because it does not need to compile and link, it can help you save some development time. The interpreter can be used interactively, which can be very convenient to test the various functions in the language to facilitate writing procedures, or to perform themselves. You can also be a calculator that is useless.

Python can write a very compact and readable program. Programs written with Python are usually much shorter than the same C or C programs, because the following reasons:

The advanced data structure allows you to express a very complex operation in a separate statement; the organization of statements depends on indentation instead of the begin / end block; no variable or parameter declaration.

Python is executable: If you will write a program with a C language, you can easily add new integrated modules and features to the interpreter, or optimize the bottleneck to achieve the maximum speed, or enable Python to be linked to the desired Binary architecture (such as a dedicated business graphics library). When you are really familiar with this, you can integrate Python into the program written by C, put Python as the extension or command line language of this program.

By the way, the name of this language comes from the BBC's "Monty Python's Flying Circus" program, and there is no relationship with ferocious crawler. Quote Monty Python allusions in the document are not only allowed, but also encouraged!

Now you have already understood all exciting things in Python, probably try it carefully. The best way to learn a language is to use it, you will be very happy.

In the next section, we will make very mechanical descriptions of the use of the interpreter. This is not mysterious, but it helps us to practice the example behind it.

This guide other portions describe the various functions of the Python language and the system, starting to be simple expressions, grammar, and data types, followed by functions and modules, and finally advanced content such as exceptions and custom classes.

转载请注明原文地址:https://www.9cbs.com/read-4569.html

New Post(0)