没有合适的资源?快使用搜索试试~ 我知道了~
首页Python学习指南:从入门到高级特性
Python学习指南:从入门到高级特性
需积分: 10 1 下载量 151 浏览量
更新于2024-07-26
收藏 557KB PDF 举报
"《Python学习手册》是一本全面介绍Python编程语言的指南,适合初学者和有经验的程序员阅读。本书从"Byte of Python"章节开始,引导读者了解Python的基础知识,包括其简洁、易学的特点,以及作为免费开源、高级且跨平台的语言,支持面向对象编程和可扩展性。书中还探讨了Python与Perl和Ruby的比较,突出其广泛适用性和丰富的库支持。 对于不同操作系统的用户,安装Python的指导很详细,包括Linux、Windows(通过DOS提示符)和MacOS X。在第一部分的“First Steps”,作者介绍了如何使用Python解释器,选择合适的文本编辑器,并编写和运行简单的源代码。此外,书中解释了如何处理数字、字符串,包括单引号、双引号、三引号的使用,以及如何处理转义序列和raw字符串,强调了字符串是不可变的特性。 深入部分,书籍介绍了如何执行Python程序,以及寻求帮助的方式。在“Basics”章节中,重点讲解了诸如常量、数值类型、字符串处理等基础知识。同时,作者还引用了程序员对Python的评价,展示了Python在实际开发中的优势和应用场景。 整个手册以清晰的结构和实用的示例,帮助读者逐步掌握Python的核心概念,无论是为了学术研究,还是为了职业发展,都是学习Python的理想资源。最后,该书还提供购买选项和下载链接,以及支持阅读者用母语阅读,让学习过程更加便捷和舒适。通过阅读《Python学习手册》,读者将建立起坚实的Python编程基础,为进一步探索高级特性和专业项目打下坚实基础。"
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/5181568/bg10.jpg)
Extensible
If you need a critical piece of code to run very fast or want to have some piece
of algorithm not to be open, you can code that part of your program in C or
C++ and then use it from your Python program.
Embeddable
You can embed Python within your C/C++ programs to give ‘scripting’ capa-
bilities for your program’s users.
Extensive Libraries
The Python Standard Library is huge indeed. It can help you do various things
involving regular expressions, documentation generation, unit testing, threading,
databases, web browsers, CGI, FTP, email, XML, XML-RPC, HTML, WAV files,
cryptography, GUI (graphical user interfaces), Tk, and other system-dependent
stuff. Remember, all this is always available wherever Python is installed. This
is called the ‘Batteries Included’ philosophy of Python. : Besides the standard
library, there are various other high-quality libraries such as wxPython , Twisted,
Python Imaging Library and many more.
Python is indeed an exciting and powerful language. It has the right combination
of performance and features that make writing programs in Python both fun
and easy.
Why not Perl?
If you didn’t know already, Perl is another extremely popular open source
interpreted programming language.
If you have ever tried writing a large program in Perl, you would have answered
this question yourself! In other words, Perl programs are easy when they are
small and it excels at small hacks and scripts to ‘get work done’. However,
they quickly become unwieldy once you start writing bigger programs and I am
speaking this out of my experience writing large Perl programs at Yahoo!
When compared to Perl, Python programs are definitely simpler, clearer, easier
to write and hence more understandable and maintainable. I do admire Perl and
I do use it on a daily basis for various things but whenever I write a program, I
always start thinking in terms of Python because it has become so natural for
me. Perl has undergone so many hacks and changes, that it feels like it is one
big (but one hell of a) hack. Sadly, the upcoming Perl 6 does not seem to be
making any improvements regarding this.
16
![](https://csdnimg.cn/release/download_crawler_static/5181568/bg11.jpg)
The only and very significant advantage that I feel Perl has, is its huge CPAN
library - the Comprehensive Perl Archive Network. As the name suggests, this is
a humongous collection of Perl modules and it is simply mind-boggling because
of its sheer size and depth - you can do virtually anything you can do with a
computer using these modules. One of the reasons that Perl has more libraries
than Python is that it has been around for a much longer time than Python.
However this seems to be changing with the growing Python Package Index.
Why not Ruby?
If you didn’t know already, Ruby is another popular open source interpreted
programming language.
If you already like and use Ruby, then I would definitely recommend you to
continue using it.
For other people who have not used it and are trying to judge whether to
learn Python or to learn Ruby, then I would recommend Python, purely from
an ease-of-learning perspective. I personally found it hard to grasp the Ruby
language, but for people who understand Ruby, they all praise the beauty of the
language. Unfortunately, I am not as lucky to have understood the beauty of
Ruby.
What Programmers Say
You may find it interesting to read what great hackers like ESR have to say
about Python:
(1)
Eric S. Raymond is the author of “The Cathedral and the Bazaar” and is
also the person who coined the term Open Source. He says that Python
has become his favorite programming language. This article was the real
inspiration for my first brush with Python.
(2)
Bruce Eckel is the author of the famous Thinking in Java and Thinking in
C++ books. He says that no language has made him more productive than
Python. He says that Python is perhaps the only language that focuses on
making things easier for the programmer. Read the complete interview for
more details.
(3)
Peter Norvig is a well-known Lisp author and Director of Search Quality
at Google (thanks to Guido van Rossum for pointing that out). He says
that Python has always been an integral part of Google. You can actually
verify this statement by looking at the Google Jobs page which lists Python
knowledge as a requirement for software engineers.
17
![](https://csdnimg.cn/release/download_crawler_static/5181568/bg12.jpg)
Installation
For Linux and BSD users
If you are using a distribution of Linux such as Ubuntu, Fedora, OpenSUSE,
Debian, CentOS or {put your choice here}, or a BSD system such as FreeBSD,
then it is most likely you already have Python installed on your system.
To test if you have Python already installed on your BSD or Linux box, open
a shell program (like
gnome-terminal
) and enter the command
python -V
as
shown below.
$ python -V
Python 2.7.2
Note:
$
is the prompt of the shell. It will be different for you depending on the
settings of the operating system on your computer, hence I will indicate the
prompt by just the $ symbol.
If you see some version information like the one shown above, then you have
Python installed already.
However, if you get a message like this one:
$ python -V
bash: python: command not found
Then you don’t have Python installed. This is highly unlikely but possible.
In this case, you have two ways of installing Python on your system.
•
Install the binary packages using the package management software that
comes with your OS, such as
apt-get
in Ubuntu/Debian and other Debian-
based distros,
yum
in Fedora,
pkg_add
in FreeBSD, etc. Note that you
will need an internet connection to use this method. Alternatively, you
can download the binaries from somewhere else and then copy to your
computer and install it.
•
You can compile Python from the source code and install it. The compila-
tion instructions are provided at the website.
For Windows Users
Visit
http://www.python.org/download/
and download the latest version. The
installation is just like any other Windows-based software.
18
![](https://csdnimg.cn/release/download_crawler_static/5181568/bg13.jpg)
Caution: When you are given the option of unchecking any “optional” com-
ponents, don’t uncheck any! Some of these components can be useful for you,
especially IDLE.
An interesting fact is that majority of Python downloads are by Windows users.
Of course, this doesn’t give the complete picture since almost all Linux users
will have Python installed already on their systems by default.
DOS Prompt
If you want to be able to use Python from the Windows command line i.e. the
DOS prompt, then you need to set the PATH variable appropriately.
For Windows 2000, XP, 2003 , click on
Control Panel
—
System
—
Advanced
—
Environment Variables
. Click on the variable named
PATH
in the ‘System
Variables’ section, then select
Edit
and add
;C:\Python27
to the end of what
is already there. Of course, use the appropriate directory name.
For older versions of Windows, open the file
C:\AUTOEXEC.BAT
and add the line
‘
PATH=%PATH%;C:\Python27
’ (without the quotes) and restart the system. For
Windows NT, use the AUTOEXEC.NT file.
For Windows Vista:
1. Click Start and choose Control Panel
2.
Click System, on the right you’ll see “View basic information about your
computer”
3.
On the left is a list of tasks, the last of which is “Advanced system settings.”
Click that.
4.
The Advanced tab of the System Properties dialog box is shown. Click the
Environment Variables button on the bottom right.
5.
In the lower box titled “System Variables” scroll down to Path and click
the Edit button.
6. Change your path as need be.
7.
Restart your system. Vista didn’t pick up the system path environment
variable change until I restarted.
For Windows 7:
1.
Right click on Computer from your desktop and select properties or Click
Start and choose Control Panel — System and Security — System. Click
on Advanced system settings on the left and then click on the Advanced
tab. At the bottom click on Environment Variables and under System
variables, look for the PATH variable, select and then press Edit.
19
![](https://csdnimg.cn/release/download_crawler_static/5181568/bg14.jpg)
2.
Go to the end of the line under Variable value and append
;C:\Python27
.
3.
If the value was
%SystemRoot%\system32;
It will now become
%SystemRoot%\system32;C:\Python27
4. Click ok and you are done. No restart is required.
For Mac OS X Users
Mac OS X Users will find Python already installed on their system. Open the
Terminal.app
and run
python -V
and follow the advice in the above Linux and
BSD section.
Summary
For Linux and BSD systems, you probably already have Python installed on your
system. Otherwise, you can install it using the package management software
that comes with your distribution. For a Windows system, installing Python is
as easy as downloading the installer and double-clicking on it. From now on, we
will assume that you have Python installed on your system.
Next, we will write our first Python program.
First Steps
We will now see how to run a traditional ‘Hello World’ program in Python. This
will teach you how to write, save and run Python programs.
There are two ways of using Python to run your program - using the interactive
interpreter prompt or using a source file. We will now see how to use both of
these methods.
Using The Interpreter Prompt
Start the interpreter on the command line by entering
python
at the shell
prompt.
For Windows users, you can run the interpreter in the command line if you have
set the PATH variable appropriately.
In order to open the command line in Windows, open the start menu and click
‘Run’. In the dialog box, type ‘cmd’ and press enter; you now have everything
you need to get started with python in the DOS prompt.
Now enter
print(’Hello World’)
followed by the
enter
key. You should see
the words Hello World as output.
20
剩余132页未读,继续阅读
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
mzy20082777
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- 解决本地连接丢失无法上网的问题
- BIOS报警声音解析:故障原因与解决方法
- 广义均值移动跟踪算法在视频目标跟踪中的应用研究
- C++Builder快捷键大全:高效编程的秘密武器
- 网页制作入门:常用代码详解
- TX2440A开发板网络远程监控系统移植教程:易搭建与通用解决方案
- WebLogic10虚拟内存配置详解与优化技巧
- C#网络编程深度解析:Socket基础与应用
- 掌握Struts1:Java MVC轻量级框架详解
- 20个必备CSS代码段提升Web开发效率
- CSS样式大全:字体、文本、列表样式详解
- Proteus元件库大全:从基础到高级组件
- 74HC08芯片:高速CMOS四输入与门详细资料
- C#获取当前路径的多种方法详解
- 修复MySQL乱码问题:设置字符集为GB2312
- C语言的诞生与演进:从汇编到系统编程的革命
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)