惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - I love I think

Tomcat 配置集锦 eclipse+tomcat python的对象与名字绑定(转贴,此文甚好) 这几天一直在看Latex,试着排版了一份试卷。 开机即打开Numlock - I love I think Keep track of own postings using Summary Highlighting (Submitted by dzimmerm on Sun, 12/28/2003 - 18:31. ) 哈夫曼树(调试没通过,郁闷) 新闻组上看到一篇关于linux内核编译的文章,留待日后参考。 调整显示屏幕偏移和刷新频率[zt] The best way to predict future is to invent it.------Alan Kay 数学学科分类标准 KMP算法 有趣的东西太多了。 nvidia驱动安装 linux内核源码目录结构 Linux打印介绍【转贴】 矩阵的相似对角化到底有什么用?该不会是纯粹的理论吧? 宫崎骏的动画片真有意思啊。 elisp1
单引号、双引号和三双引号的区别 - I love I think
I love I thi · 2005-04-15 · via 博客园 - I love I think


先说1双引号与3个双引号的区别,双引号所表示的字符串通常要写成一行
如:
s1 = "hello,world"
如果要写成多行,那么就要使用\ (“连行符”)吧,如
s2 = "hello,\
world"
s2与s1是一样的。如果你用3个双引号的话,就可以直接写了,如下:
s3 = """hello,
world,
hahaha.""",那么s3实际上就是"hello,\nworld,\nhahaha.", 注意“\n”,所以,
如果你的字符串里\n很多,你又不想在字符串中用\n的话,那么就可以使用3个双
引号。而且使用3个双引号还可以在字符串中增加注释,如下:
s3 = """hello,  #hoho, this is hello, 在3个双引号的字符串内可以有注释哦
world,          #hoho, this is world
hahaha."""
这就是3个双引号和1个双引号表示字符串的区别了,3个双引号与1个单引号的区别也

是和这个一样的,实际上python支持单引号是有原因的,下面我来比较1个单引号和
1个双引号的区别。


当我用单引号来表示一个字符串时,如果要表示 Let's go 这个字符串,必须这样:
s4 = 'Let\'s go',注意没有,字符串中有一个',而字符串又是用'来表示,所以
这个时候就要使用转义符 \ (\,转义符应该知道吧), 如果你的字符串中有一大堆
的转义符,看起来肯定不舒服,python也很好的解决了这个问题,如下:
s5 = "Let's go"
这时,我们看,python知道你是用 " 来表示字符串,所以python就把字符串中的那
个单引号 ' , 当成普通的字符处理了,是不是很简单。
对于双引号,也是一样的,下面举个例子
s6 = 'I realy like "python"!'
这就是单引号和双引号都可以表示字符串的原因了。

posted on 2005-04-15 23:26  I love I think  阅读(28446)  评论()    收藏  举报