【Python3.72官方文档】——引言

英文原文

If you do much work on computers, eventually you find that there’s some task you’d like to automate. For example, you may wish to perform a search-and-replace over a large number of text files, or rename and rearrange a bunch of photo files in a complicated way. Perhaps you’d like to write a small custom database, or a specialized GUI application, or a simple game.

If you’re a professional software developer, you may have to work with several C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is too slow. Perhaps you’re writing a test suite for such a library and find writing the testing code a tedious task. Or maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application.

Python is just the language for you.

You could write a Unix shell script or Windows batch files for some of these tasks, but shell scripts are best at moving around files and changing text data, not well-suited for GUI applications or games. You could write a C/C++/Java program, but it can take a lot of development time to get even a first-draft program. Python is simpler to use, available on Windows, Mac OS X, and Unix operating systems, and will help you get the job done more quickly.

Python is simple to use, but it is a real programming language, offering much more structure and support for large programs than shell scripts or batch files can offer. On the other hand, Python also offers much more error checking than C, and, being a very-high-level language, it has high-level data types built in, such as flexible arrays and dictionaries. Because of its more general data types Python is applicable to a much larger problem domain than Awk or even Perl, yet many things are at least as easy in Python as in those languages.

Python allows you to split your program into modules that can be reused in other Python programs. It comes with a large collection of standard modules that you can use as the basis of your programs — or as examples to start learning to program in Python. Some of these modules provide things like file I/O, system calls, sockets, and even interfaces to graphical user interface toolkits like Tk.

Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary. The interpreter can be used interactively, which makes it easy to experiment with features of the language, to write throw-away programs, or to test functions during bottom-up program development. It is also a handy desk calculator.

Python enables programs to be written compactly and readably. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for several reasons:

the high-level data types allow you to express complex operations in a single statement;
statement grouping is done by indentation instead of beginning and ending brackets;
no variable or argument declarations are necessary.
Python is extensible: if you know how to program in C it is easy to add a new built-in function or module to the interpreter, either to perform critical operations at maximum speed, or to link Python programs to libraries that may only be available in binary form (such as a vendor-specific graphics library). Once you are really hooked, you can link the Python interpreter into an application written in C and use it as an extension or command language for that application.

By the way, the language is named after the BBC show “Monty Python’s Flying Circus” and has nothing to do with reptiles. Making references to Monty Python skits in documentation is not only allowed, it is encouraged!

Now that you are all excited about Python, you’ll want to examine it in some more detail. Since the best way to learn a language is to use it, the tutorial invites you to play with the Python interpreter as you read.

In the next chapter, the mechanics of using the interpreter are explained. This is rather mundane information, but essential for trying out the examples shown later.

The rest of the tutorial introduces various features of the Python language and system through examples, beginning with simple expressions, statements and data types, through functions and modules, and finally touching upon advanced concepts like exceptions and user-defined classes.

中文翻译

如果你在电脑上做了很多工作,最终你会发现有一些任务你想要自动化。例如,你可能希望对大量的文本文件执行搜索和替换,或者以复杂的方式重命名并排列一堆照片文件。也许你想写一个小的自定义数据库,或专门的GUI应用程序,或一个简单的游戏。

如果你是一个专业的软件开发人员,您可能必须使用几个 C / C + + /Java 库,但发现通常的编写/编译/测试/重新编译周期太慢。也许你要写这样的库中的测试套件,然后发现编写测试代码是很乏味的工作。或许您编写了一个程序,它可以使用一种扩展语言,但你不想为您的应用程序来设计与实现一个完整的新语言。

Python正是你所需要的语言。

你可以为其中一些任务写一个 Unix shell 脚本或 Windows 批处理文件,但是 shell 脚本最适合处理文件移动和文本编辑,而不适用于 GUI 应用程序和游戏。你可以用C / C + +/Java写一个 程序,但是可能会花费大量的开发时间去完成一份初稿。Python更易于使用,在Windows,Mac OS X和Unix操作系统上可用,并且将帮助您更快地完成工作。

Python使用起来很简单,但它是一种真正的编程语言,与shell脚本或批处理文件相比,它可以为大型程序提供更多的结构和支持。另一方面,Python还提供比C更多的错误检查,并且作为非常高级语言,它具有内置的高级数据类型,例如灵活的数组和字典。因为其丰富的更加通用的数据类型, Python 的适用领域比 Awk 甚至 Perl 要广泛得多,而且很多事情在 Python 中至少和那些语言一样容易。

Python 允许您将您的程序拆分成可以在其他 Python 程序中再次使用的模块。它有一大批的标准模块,你可以用它作为你的程序的基础 - 或者作为例子开始学习使用Python编程。这些模块提供诸如文件 I/O、 系统调用、 套接字,甚至还为像 Tk 这样的图形界面开发包提供了接口。

Python 是一门解释性的语言,因为没有编译和链接,它可以节省你程序开发过程中的大量时间。Python 解释器可以交互地使用,这使得试验Python语言的特性、编写用后即扔的程序或在自底向上的程序开发中测试功能非常容易。它也是一个方便的桌面计算器。

Python 使程序编写起来能够简洁易读。编写的 Python 程序通常比等价的 C、 C + + 或 Java 程序短很多,原因有几个:

高级数据类型允许您在单个语句中来表达复杂的操作;
语句分组是通过缩进,而不是开始和结束的括号 ;
不需要为变量或参数进行声明。
Python是可扩展的:如果你会C语言,可以很容易地向解释器添加一个新的内建函数或模块,以最快速度执行关键操作,或者链接Python程序到只能以二进制形式可用的库(例如供应商特定的图形库)。一旦你真的着迷,你可以把 Python 解释器链接到 C 编写的应用程序中,并把它当作那个程序的扩展或命令行语言。

顺便说一句,Python 语言的名字来自于BBC 的 “Monty Python’s Flying Circus” 节目,与爬行动物无关。我们不仅允许,甚至鼓励您在代码中引用Monty Python短剧!

既然现在你们都为 Python 感到兴奋,你们一定会想更加详细地研究它。学习一门语言最好的方法就是使用它,本教程推荐你边读边使用 Python 解释器练习。

在下一章中,我们将解释 Python 解释器的用法。这是很简单的一件事情,但它有助于试验后面的例子

本教程的其余部分通过实例介绍了 Python 语言和体系的各种特性,以简单的表达式、 语句和数据类型开始,然后是 函数和模块,最后讲述高级概念,如异常和用户自定义的类。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值