ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Core Python | 2 - Core Python: Getting Started | 2.4 - Introducing Strings, Collections, and Iterati

2021-02-18 05:32:04  阅读:249  来源: 互联网

标签:styles Core Python quoting character quotes literal 2.4


Strings in Python have the data type str, spelled s‑t‑r, and we've been using them extensively already. Strings are sequences of Unicode code points, and for the most part, you can think of code points as being like characters, although they are not strictly equivalent. The sequence of characters in a Python string is immutable, meaning that once you've constructed a string, you can't modify its contents. Literal strings in Python are delimited by quotes, you could use single quotes or double quotes. You must, however, be consistent. For example, you can't use single quotes on one side and double on the other, like this. Supporting both quoting styles allows you to easily incorporate the other quote character into the literal string without resorting to ugly escape character. Notice that the REPL exploits the same quoting flexibility when echoing the strings back to us. Beautiful text strings rendered in literal form, simple elegance. At first sight, support for both quoting styles seems to violate an important principle of Pythonic style from the Zen of Python. There should be one, and preferably only one, obvious way to do it. In this case, however, another aphorism from the same source, practicality beats purity, takes precedence. The utility of supporting two quoting styles is valued more highly than the alternative, a single quoting style combined with more frequent use of ugly escape sequences, which we'll encounter shortly.

 

extensively 广泛地
equivalent 相等地
immutable 不可变的
delimit 界定
quote 引号
escape character 转义字符
literal 文字的,字面的
literal form 字面形式
take precedence 优先
rendered in literal form 以字面形式呈现
simple elegance 简单的优雅
at first sight 乍一看
violate an important principle 违反了重要的原则
preferably only one 只有一个更好/最好也只有一个
aphorism 格言
practicality beats purity 实用大于纯粹
we'll encounter shortly 我们很快就会遇到
alternative 二选一

标签:styles,Core,Python,quoting,character,quotes,literal,2.4
来源: https://www.cnblogs.com/hmlhml/p/14410444.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有