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

python 基础知识一、

2016-03-16 20:56 288 查看
常见字符串常量和表达式

操作 解释

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)

本文出自 “赶不上的脚步” 博客,请务必保留此出处http://xxmspace.blog.51cto.com/1056016/1751917
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: