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版)
50
第
5
章
字符串
我一直喜欢奇怪的角色。
——
T
im Burton
计算机类图书通常给人留下一种印象:编程与数学休戚相关。实际上,大多数程序员跟
字
符串
打交道的时间要远多于数字。逻辑(以及创造性!)思维往往比数学技能更重要。
字符串是
Python
中
序列
的第一个例子。字符串就是
字符
序列。那什么是字符呢?字符是书
写系统的最小单位,不仅包括字母、数字、符号、标点,甚至包括空白或类似换行这样的
指令。字符是由其意义(用途)而不是外形定义的。字符可以有多种视觉表现形式(不同
的
字体
),而且多个字符可以具有相同的外观(比如
H
,在拉丁字母中发
H
的音,而在西里
尔字母中发拉丁字母
N
的音)。
本章使用
ASCII
(基本字符集)示例
,重点介绍如何创建和格式化简单的文本字符串。另
外两个重要的文本主题留待第
12
章讨论
,它们是
Unicode
字符(就像刚才说到的字符
H
和
N
的问题)和
正则表达式
(模式匹配)。
不同于其他语言,
Python
中的字符串是
不可变
的。你无法就地修改字符串,但是可以将部
分字符串复制为另一个字符串,以获得相同的效果。接下来会介绍该如何实现。
5.1
使用引号创建字符串
可以把若干个字符放进一对单引号或双引号中来创建
Python
字符串:
>>> 'Snap'
'Snap'
>>> "Crackle"
'Crackle'
字符串
|
51
交互式解释器输出的字符串使用的是单引号,但无论是哪种引号,
Python
都一视同仁。
Python
有几种特殊类型的字符串,由引号前的第一个字母指明。
f
或
F
表示
用于格式化的
f
字符串,本章末尾会介绍。 ...
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