Python学习笔记——字符串
2016-03-23 19:39
393 查看
Python学习笔记——字符串
字符串类型转义字符
字符串的处理方法
字符串的索引
Python学习笔记字符串
字符串类型
转义字符
字符串的处理方法
字符串类型
字符串是用双引号或单引号括起来的一个或多个字符。字符串可以保存在变量中,也可以单独存在。
可以用type()函数测试一个字符串的类型。
转义字符
转义符可以在字符串中表达一些不可直接打印的信息。e.g. 用\n表示换行。
字符串“hello\nworld”,打印的结果为hello 和 world各占一行。
# -*- coding: utf-8 -*- """ Created on Wed Mar 23 13:20:16 2016 @author: Zhiqiang """ print("hello\nworld\n") print("hello\tworld")
字符串的处理方法
Python 字符串处理方法:<string>.func()
Operation | Implication |
---|---|
<string>.upper() | 字符串中字母大写 |
<string>.lower() | 字符串中字母小写 |
<string>.capitalize() | 首字母大写 |
<string>.strip() | 去两边空格及去指定字符 |
<string>.split() | 按指定字符分隔字符串为数组 |
<string>.isdigit() | 判断是否是数字类型,如果是真true,否则false |
<string>.find() | 搜索指定字符串 |
<string>.replace() | 字符串替换 |
<string>.len() | 返回字符串长度。 |
<string> + <string> | 字符串拼接 |
number * <string> | 重复母字符串 |
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法