python 基础知识一、
2016-03-16 20:56
344 查看
常见字符串常量和表达式
操作 解释
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
操作 解释
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
相关文章推荐
- python 几个常用问题代码示例(未完,待续)
- Falcon - The minimalist Python WSGI framework
- 第四部分:python性能技巧
- 第三部分:Python基本数据类型
- python中下划线,双下划线,首尾双下划线的区别(Difference between _, __ and __xx__ in Python)
- 第二部分:python 常用操作与函数
- 第一部分 python基础
- Python抓取中文网页
- 阿里大鱼短信接口(Python3版)
- python show-me-the-code 第0011题
- Python的高级Git库 Gittle_python_脚本之家
- python工具记录
- python 文件操作seek() 和 telll() 自我解释
- python的二维数组操作
- Python基础——python学习图谱
- Python爬虫_简单获取百度贴吧图片
- Python学习之常用内置模块:urlib
- python Custom template tags and filters is not a valid tag library
- [python]我的第一只爬虫
- Python3.x爬虫教程:爬网页、爬图片、自己主动登录