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
Luciano Ramalho
April 2023
Intermediate to advanced
769 pages
25h 16m
Chinese
Posts & Telecom Press
Content preview from
流畅的Python(第2版)
175
第
7
章
函数是一等对象
不管别人怎么说或怎么想,我从未觉得
Python
受到函数式语言太多的影响。我
非常熟悉像
C
和
Algol
68
这样的命令式语言。虽然我把函数定为一等对象,但是
并不把
Python
当作函数式编程语言。
——
Guido van Rossum
Python
仁慈的“独裁者”
1
在
Python
中,函数是一等对象。编程语言研究人员把“一等对象”定义为满足以下条件的
程序实体:
•
在运行时创建;
•
能赋值给变量或数据结构中的元素;
•
能作为参数传给函数;
•
能作为函数的返回结果。
在
Python
中
,整数、字符串和字典都是一等对象——没什么特别的。像
Clojure
、
Elixir
和
Haskell
这
样的函数式语言均把函数当作一等对象。不过,由于一等函数是个非常有用的功
能,因此像
JavaScript
、
Go
和
Java
(自
JDK 8
起)这样的流行语言也采用了这种设计
,但
这些语言都不算“函数式语言”。
本章以及第三部分的大多数章会探讨把函数视为对象的现实意义。
人们经常将“把函数视为一等对象”简称为“一等函数”。这样说并不完美,
似乎表明这是函数中的特殊群体。在
Python
中,所有函数都是一等对象。
注
1
:
摘自
Guido
的
The History of Python
博客,题为“
Origins of Python
’
s
‘
Functional
’
Features
”。
176
|
第
7
章
7.1
本章新增内容
本书第
1
版中的
5.4
节,即“
7
种可调用对象”,在第
2
版中变成了“
9
种可调用对象”。新
增的可调用对象是原生协程和异步生成器,分别由 ...
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高级编程(第2版)
Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Python语言及其应用(第2版)
Bill Lubanovic
Kafka权威指南(第2版)
Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
Python贝叶斯分析(第2版)
Posts & Telecom Press, Osvaldo Martin
Publisher Resources
ISBN: 9787115612366