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版)
22
2
2.4
字面值
Python
中,指定数值的方法有两种。
字面值
变量
后面的章节会详细介绍如何指定不同类型的字面值:整数是数位序列,浮点数包含一个小数
点,文本字符串两边是引号,等等。但是,在本章的其余部分,为了舒缓一下手指,我们的
例子只使用简短的十进制整数和一两个
Python
列表
。十进制整数和数学中的整数一样,都是
0
9
的数位序列。和整数相关的一些额外细节(比如符号和非
10
基数
)
,请参见第
3
章。
2.5
变量
下面来讲一个计算机语言中的重要概念。
和大多数计算机语言一样,
Python
也允许你定义
变量
——在程序中为了引用内存中的值而
为其取的名称。
Python
变量名有如下规则。
只能包含下列字符。
小写字母(
a~z
大写字母(
A~Z
数字(
0~9
下划线(
_
区分大小写:
thing
Thing
THING
是不同的名称。
必须以字母或下划线起始,而不能是数字。
以下划线起始的名称会做特殊处理(参见第
9
)。
不能是
Python
保留字
(也称为
关键字
)。
Python
的保留字
3
如下:
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
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