Skip to Content
Python语言及其应用(第2版)
book

Python语言及其应用(第2版)

by Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from Python语言及其应用(第2版)
28
2
列表
是值的可变数组,第
7
章会详细介绍
。在这个例子中,
a
b
均指向一个包含
3
个整
数的列表:
>>> a = [2, 4, 6]
>>> b = a
>>> a
[2, 4, 6]
>>> b
[2, 4, 6]
列表成员(
a[0]
a[1]
a[2]
)的作用类似于名称,分别指向值为
2
4
6
的整数对象。
列表对象会保持其成员的顺序。
通过名称
a
修改第一个列表元素,
b
也会随之发生变化:
>>> a[0] = 99
>>> a
[99, 4, 6]
>>> b
[99, 4, 6]
当第一个列表元素被修改时,它就不再指向值为
2
的对象了,而是指向另一个值为
99
新对象。列表的类型依然是
list
,但它的值(列表元素及其顺序)是可变的。
2.11
选个好变量名
他说的是实情,却叫错了名字。
——
Elizabeth Barrett Browning
选一个好变量名的重要性出乎你的意料。在目前很多示例代码中,我使用的是像
a
x
种用完就扔的名称。在真实程序中,要同时跟踪的变量有很多,你需要在简洁和清晰之间
做出平衡。例如,输入
num_loons
肯定要比
number_of_loons
gaviidae_inventory
省事,
但它比
n
更明晰。
2.12
后续内容
数字!它们和你预想的一样令人兴奋。好吧,也许只是没那么糟糕吧。
5
你将看到如何将
Python
作为一个计算器使用,以及一只猫咪如何建立一套数字系统。
2.13
练习
1.
将整数值
99
赋给变量
prince
并打印该变量。
2.
数值
5
是什么类型?
3.
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

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham
量子计算机编程:从入门到实践

量子计算机编程:从入门到实践

Eric R. Johnston, Nicholas Harrigan, Mercedes Gimeno-Segovia
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787115586223