Skip to Content
Python入门指南, 3rd Edition
book

Python入门指南, 3rd Edition

by Bill Lubanovic
September 2025
Intermediate to advanced
660 pages
7h 15m
Chinese
O'Reilly Media, Inc.
Content preview from Python入门指南, 3rd Edition

附录。 练习答案

2.类型和变量

2.1 如果您的计算机上还没有安装 Python,现在就安装吧。 请阅读第 1 章,了解计算机系统的详细信息。

2.2 启动 Python 交互式解释器。 详细信息请参见第 1 章。解释器应该打印几行关于它自己的内容,然后打印一行以>>> 开头的内容。这就是输入 Python 命令的提示。

2.3 稍微玩一下解释器。 像使用计算器一样,输入:8 * 9 。按 Enter 键查看结果。 Python 应该打印72

2.4 键入数字47 并按 Enter 键。是否在下一行打印出 47?

现在输入print(47) 并按回车键。下一行是否也打印出 47?

3.数字

3.1 一小时有多少秒? 使用交互式解释器作为计算器,用一分钟中的秒数 (60) 乘以一小时中的分钟数(也是60 )。

3.2 将上一任务的结果(一小时中的秒数)赋值给一个名为seconds_per_hour 的变量。

3.3 一天有多少秒?使用seconds_per_hour 变量。

3.4 再次计算每天的秒数,但这次要将结果保存到名为seconds_per_day 的变量中。

3.5 用seconds_per_day 除以seconds_per_hour 。使用浮点数 (/) 除法。

3.6 用seconds_per_day 除以seconds_per_hour ,使用整数 (//) 除法。除了最后的.0 之外,这个数字与上一题中的浮点数一致吗?

4.字符串

4.1 以m 开头的单词大写:

>>> song = """When an eel grabs your arm,
... And it causes great harm,
... That's - a moray!"""
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

生成式人工智能设计模式

生成式人工智能设计模式

Valliappa Lakshmanan, Hannes Hapke

Publisher Resources

ISBN: 9798341668898