#字符串按空格分成列表split() print("fu li mei".split()) #split按空格分成列表 print("1+a+2+b".split('+')) #split按空格分成列表#应用场景--只提取数字 #加密密码 p=str.maketrans("hgx",'123') print("zhangsan xing".translate(p))…
1.字符串 <string>.strip() 去掉两边空格及去指定字符 <string>.split() 按指定字符分隔字符串为数组 <string>.isdigit()判断是否为数字类型 字符串操作集:http://www.cnpythoner.com/wiki/string.html tt=322 tem='%d' %tt tem即为tt转换成的字符串 字符串长度len(tt) import string f2 = string.atof(a1) 列表转字符串: d…
直接上代码!!!   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type 'str'> {'age': 7, 'name': 'Zara', 'class': 'First…
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type 'str'> {'age': 7, 'name': 'Zara', 'class': 'First'} print type(str(dict)), str(dict) #字典可以转为元组,返回:('age', 'name', 'class') print tuple(dict) #字典可以转为元组,返回…
#1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type 'str'> {'age': 7, 'name': 'Zara', 'class': 'First'} print type(str(dict)), str(dict) #字典可以转为元组,返回:('age', 'name', 'class') print tuple(dict) #字典可以转为元组,返回:(7, 'Zara', 'First'…
常用字符串操作函数: #Author:CGQ name="I \tam ChenGuoQiang" print(name.capitalize())#首字母大写,其他都小写 print(name.count("a"))#计算a的个数 print(name.center(50,"-"))#一共打印50字符,不够的用"-"补上,并居中 print(name.endswith("ex"))#是否以ex结尾 pri…
一.关于字符串的整理总结 对于字符串的操作常用的有这些: 字符串的操作通过dir()函数可以查看 我们先整理没有下划线的用法,有下划线的暂时不去考虑. 1.capitalize 功能:使字符串的首字母大写 例如: >>> name = "sanjiang">>> name.capitalize()'Sanjiang' 2.casefold 功能:使字符串的首字母小写 例如: >>> name = "Sanjiang&quo…
[C++实现python字符串函数库]split()与rsplit()方法 前言 本系列文章将介绍python提供的字符串函数,并尝试使用C++来实现这些函数.这些C++函数在这里做单独的分析,最后我们将把这些函数放在命名空间中,真正作为一个函数库来使用. 本节内容 在本节,我们将实现两个python字符串分割函数.这两个函数的函数原型为: split(spe = None,maxsplit= -1) rsplit(spe= None ,maxsplit = -1) 这两个方法使用参数spe作为…
Python第五天   文件访问    for循环访问文件    while循环访问文件   字符串的startswith函数和split函数  linecache模块 目录 Pycharm使用技巧(转载) Python第一天  安装  shell  文件 Python第二天  变量  运算符与表达式  input()与raw_input()区别  字符编码  python转义符  字符串格式化 Python第三天 序列  5种数据类型  数值  字符串  列表  元组  字典 Python第四…
Python中常见字符串去除空格的方法总结 1:strip()方法,去除字符串开头或者结尾的空格>>> a = " a b c ">>> a.strip()'a b c'2:lstrip()方法,去除字符串开头的空格>>> a = " a b c ">>> a.lstrip()'a b c '3:rstrip()方法,去除字符串结尾的空格>>> a = " a b c…