06Python中的string数据类型
来源:互联网 发布:中国人 知乎 编辑:程序博客网 时间:2024/05/16 05:36
#-*- coding:UTF-8-*-# 1.Python不支持单字符类型,单字符也在Python也是作为一个字符串使用。str1 = 'hello, world'print str1[1]print str1[1:3]print str1[0:5] + 'CC'# 2.Python可以使用转义字符print str1 + '\t\t' + str1# 3.字符串操作str1 = 'Hello'str2 = 'World'print str1 + ' ' + str2print str1 * 2 # 重复输出print str1[0]print str1[0:4]print 'He' in str1 # 成员运算符in,是否包含给定字符print 'ls' not in str1 # 成员运算符not inprint R'\r\n\t' # 输出原始字符串,不进行转义# 4.格式化字符串# %s字符串, %d整数,%f浮点数print "My name is %s and weight is %d kg!" %('Zara', 21)# 5.三引号# 三引号允许一个字符串跨多行,字符串中可以包含换行符、制表符以及其他特殊字符。# 三引号让程序员从引号和特殊字符串的泥潭里面解脱出来,自始至终保持一小块字符串的格式是所谓的WYSIWYG(所见即所得)格式的。str3 = '''<HTML><HEAD><TITLE>Friends CGI Demo</TITLE></HEAD><BODY><H3>ERROR</H3><B>%s</B><P><FORM><INPUT TYPE=button VALUE=BackONCLICK="window.history.back()"></FORM></BODY></HTML>'''print str3# 6.Unicode字符串# 引号前小写的"u"表示这里创建的是一个 Unicode 字符串。print u"hello\u0020" # 被替换的 \u0020 标识表示在给定位置插入编码值为 0x0020 的 Unicode 字符(空格符)。# 7.字符串内建函数
阅读全文
0 0
- 06Python中的string数据类型
- Python数据类型String字符串
- Java中的String数据类型
- Java中的String数据类型
- Java中的String数据类型
- Java中的String数据类型
- 【python】python中的数据类型
- python 中的 数据类型
- python中的数据类型
- Python中的重要数据类型
- python中的数据类型
- python中的基本数据类型
- Python中的数据类型
- Python中的数据类型
- Python中的数据类型
- Python中的数据类型
- Python中的数据类型
- Java中的String数据类型归纳
- 量子计算
- 最长公共子串(动态规划)
- Java项目中几个常用的数组排序
- 点菜系统数据流图
- 请统计"nba"在字符串"nbaernbatynbauinbaopnba"中出现的次数
- 06Python中的string数据类型
- 【转】研究的重点内容 (博客)
- 51nod 1050 循环数组最大子段和 !!!!巧妙
- (angularjs) 数据的增查(添加用户,查询名字,实现排序,判断非空 ,是否是数字,是否重名,敏感字符)
- 企业绩效(笔记)
- Pycharm2017更改主题
- 论文阅读:《Towards accurate multi-person pose estimation in the wild》CVPR 2017
- <leetcode>637. Average of Levels in Binary Tree
- 【nginx+tomcat】轻松搭建高性能负载均衡集群