您的位置:首页 > 编程语言 > Python开发

【语言处理与Python】3.2字符串:最底层的文本处理

2013-05-24 16:06 309 查看

字符串的基本操作

#字符串跨行(这种方式不会有换行,简单的字符串连接)

Couplet=”Shall I compare thee to a Summer’s day?"\

“Thou are more lovely and more temperate:”

Couplet=(“Rough winds do shake the darling buds of May,”

“And Summer’s lease hath all too short a date:”)

#如果想包含换行,可以使用三重引号

Couplet=”””Shall I compare thee to a Summer’s day

Thou are more lovely and more temperate:”””


输出字符串

print monty+grail

print monty,grail


访问单个字符

Monty[20] monty[-1]

访问子字符串

Monty[6:10] monty[:5] monty[1:]

更多的字符串操作



链表与字符串的差异

链表和字符串都是一种序列;

都可以使用切片;

链表是可以操作,可变的;

而字符串是不可变的;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: