《Python核心编程》第1章答案

来源:互联网 发布:itx电源网络唤醒 编辑:程序博客网 时间:2024/06/01 09:20

1-1

1-2

1-3: 

Python 标准库
(a)请找到系统中 Python执行程序的安装位置和标准库模块的安装位置

(b)看看标准库里的一些文件,比如 string.py。这会帮助你适应阅读 Python 脚本。

Answer:

(a)执行程序安装位置:

▶ which python

/usr/bin/python

标准库模块的安装位置:

python

Python 2.7.10 (default, Jul 30 2016, 18:31:42) 

[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import sys

>>> sys.path

['', '/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Users/yangzhen/Library/Python/2.7/lib/python/site-packages', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

(b)略

1-4

交互执行。启动你的 Python交互解释器。你可以通过输入完整的路径名来启动当然果你已经在搜索路径中设置了它的位那么只输入它的名字(python python.exe)就行了。(你可以任选最适合你的的 Python实现方式,例如:命令行、图形用户接口/集成开发环境、JythonIronPython或者 Stackless)启动界面看上去就像本章描述的一样,一旦你看到>>>提示符,就意味着解释器准备好要接受你的 Python 命令了。

试着输入命令print'HelloWorld!'(然后按回车键),完成著名的HelloWorld!程序,然后退出解释器。在 Unix系统中,按下 Ctrl+D会发送 EOF 信号来中止 Python解释器,在 DOS系统中,使用的组合键是Ctrl+Z。如果要从MacintoshPythonWin、以及WindowsUnix IDLE这样的图形用户环境中退出,只要简单的关闭相关窗口就可以了。

answer:

python

Python 2.7.10 (default, Jul 30 2016, 18:31:42) 

[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> print 'Hello World'

Hello World

>>> ^D


~                                                                              

▶ 


>>> 


1-5略
1-6略







-- NORMAL --
原创粉丝点击