Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
Python语言及其应用(第2版)
by
Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from
Python语言及其应用(第2版)
数据:类型、值、变量和名称
|
23
下面这些都是有效名称。
•
a
•
a1
•
a_b_c___95
•
_abc
•
_1a
下面这些都是无效名称。
•
1
•
1a
•
1_
•
name!
•
another-name
2.6
赋值
在
Python
中,可以使用
=
为变量赋值。
我们在小学算术中都学过,
=
表示
等于
。那么为什么包括
Python
在内的许多
计算机语言使用
=
进行赋值呢?原因之一是,标准键盘缺乏逻辑上的替代方
案,比如左箭头键,而
=
似乎也没那么让人困惑。另外,在计算机程序中,
赋值操作远比等量测试用得多。
程序不同于代数,你在学校学习数学的时候,看到的方程是这样的:
y = x + 12
可以通过为
x
代入值来解这个方程。如果将
5
代入
x
,
5 + 12
等于
17
,所以
y
的值是
17
。
将
6
代入
x
的话,
y
的值则为
18
,以此类推。
计算机程序语句看起来像方程,但含义完全不同。在
Python
和其他计算机语言中
,
x
和
y
是
变量
。
Python
知道像
12
或
5
这样的纯数位序列是整数。下面这个小
Python
程序模拟了
方程,打印出
y
的结果:
>>> x = 5
>>> y = x + 12
>>> y
17
这是数学和程序之间的一个很大的不同。在数学中,
=
代表两侧的
等量关系
;在程序中,
=
则表示
赋值
:将右侧的值赋给左侧的变量。
另外,在程序中,右侧的一切都需要有值(这称为
初始化
)。右侧既可以是字面值,也可
以是已经赋过值的变量,或是二者的组合。
Python
知道
5
和
12
都是字面整数。第一行将
整数值
5
赋给变量
x
。现在可以在下一行中使用变量 ...
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.
Start your free trial
You might also like
Python编程入门与实战
Posts & Telecom Press, Fabrizio Romano
Python实用技能学习指南
Posts & Telecom Press, Robert Smallshire, Austin Bingham
Python技术基础视频教程
保罗·J·戴特尔
Python面向对象编程指南
Posts & Telecom Press, Steven F. Lott
Publisher Resources
ISBN: 9787115586223