常见字符串常量和表达式


操作                        解释


s= ''                       空字符

s= "spam's"                    双引号和单引号相同

S = 's\np\ta\x00m'                 转义序列

s = """..."""                    三重引号字符串块

s= r'\temp\spam'                  Raw字符串

S = b'spam'                    Python3.0中的字符串

s = u'spam'                    仅在Python2.6中使用的Unicode字符串


S1 + S2                      合并

s * 3                       重复                  

s [i]                       索引

s[i:j]                      分片

len(s)                      求长度  

"a %s parrot" % kind                字符串格式化表达式

"a {0} parrot".format(kind)

s.find('pa')                    字符串方法调用:搜索

s.rstrip()                    移除空格

s.repleace('pa','xx')               替换

s.split(',')                    用展位符分隔

s.isdigit()                     内容测试

s.lower()                     短信息转换

S.endswith('spam')                结束测试

'spam'.join(strlist)                插入分隔符

S.encode('latin-1')                Unicode编码等

for x in S: print(x)                迭代,成员关系

'spam' in S

[c *2 for c in S]

map(ord, S)