# str 类,字符串
# name ='alex' # 首字母变大写
# test ='alex'
# v= test.capitalize()
# print(v)
#
# 大写全部变小写
# test ='aLExALEX'
# v= test.lower()
# print(v)
# 功能与lower的效果一样。但如果是他国的语言casefold比lower效果更好。
# test ='alexALEX'
# v= test.casefold()
# print(v) # 大小写转换: 大写变小写 小写变大写
# test ='alexXXFFFEe'
# v = test.swapcase()
# print(v)
#
#
# 从开始往后找,找到第一个之后,获取其未知
# > 或 >=
# test ='penphypenphy'
# v = test.find('e',5,8)
# print(v)
# 输出7
#
#
# 格式化,将一个字符串
# test ='i am {name},age {a}'
# print(test)
# v = test.format(name='penphy',a='19')
# print(v)
#
# 下面的例子得 count是计算p在 penphy字符串中出现的次数,从多少至多少
# test = 'penphy'
# v = test.count('p',0,100)
# print(v) # 设置宽度并将内容居中
# 20 代指总长度
# 空白未知填充,一个字符,可有可无
# test ='penphy'
# v = test.center(20,'*')
# print(v)
# 输出:*******penphy******* # ljust是把字放左边
# test ='alex'
# v =test.ljust(20,'*' )
# print(v)
# 输出:alex**************** # rjust是把字放右边
# v1 =test.rjust(20,'*')
# print(v1)
# 输出:****************alex # 只能用0来填充,不怎么使用
# test ='penhy'
# v = test.zfill(8)
# print(v)
# 输出:000penhy # expandtabs,断句20.比如tab会补齐username缺的空格,以此类推
# test = 'username\temail\tpassword\nlaiying\tying@qq.com\t123\nlaiying\tying@qq.com\t123\nlaiying\tying@qq.com\t123'
# v= test.expandtabs(20)
# print(v)
#
#
# 检测字符串中是否只包含 字母和数字
# test = 'abc123'
# v = test.isalnum()
# print(v)
# 检测字符串中是否只由字母组成
# test = 'penophy'
# v = test.isalpha()
# print(v)
#
# 判定字符串里输入的是否是数字
# test ='二'
# v1 = test.isdecimal() 十进制的小数,但不支持中文表示的数字
# v2 =test.isdigit() 支持特殊的符号,但不支持中文表示的数字
# v3 =test.isnumeric() 全都支持
# print(v1,v2,v3) # 字母,数字,下划线 :数字不能开头 只要符合这个条件的 就是 '标识符' def class符合前面的规则 比如:
# a ='123'
# v =a.isidentifier()
# print(v)
#
# import keyword
# print(keyword.iskeyword('def'))
# test ='def'
# v =test.isidentifier()
# print(v) # 是否存在不可显示的字符
# \t 制表符
# \n 换行
# test ='asdasdsad\n'
# v =test.isprintable()
# print(v) # 判断是否全部是空格
# test =' '
# v =test.isspace()
# print(v) # 判断是否是标题,首字母需大写
# test = 'Return True if all characters in S are alphabetic'
# v1 = test.istitle()
# print(v1) False
# v2 = test.title()
# print(v2) Return True If All Characters In S Are Alphabetic
# v3 = v2.istitle()
# print(v3) True
# 输出: ↑ # 将字符串中的每一个元素按照指定分隔符进行拼接-----重要
# test = '你是风儿我是沙'
# print(test)
# t =' '
# v = ' '.join(test)
# print(v) # 判断是否全部为大小写 和 转换为大小写
# test ='Alex'
# v1 =test.islower()
# v2 =test.lower()
# print(v1,v2)
# 输出:False alex
# v1 =test.isupper()
# v2 =test.upper()
# print(v1,v2)
# 输出:False ALEX # 去除左边空白
# test ='alex'
# v =test.lstrip()
# print(v)
# 去除右边的空白
# v =test.rstrip()
# print(v)
# 去除两边的空白
# v=test.strip()
# print(v) # test ='\nalex'
# print(test)
# 去除\t,\n
# v =test.lstrip()
# print(v) # 移除指定字符串
# 有限匹配↓
# 去除左边的指定字符
# test ='xalex'
# v= test.lstrip('xa')
# print(v)
# 输出:lex
# 去除右边的指定字符 先进行最多匹配
# v= test.rstrip('9lexxex')
# print(v)
# 输出:xa
# 去除两边的指定字符
# v1 =test.strip('x')
# print(v1)
# 输出:ale # v ="eawesadasdasgffdgsergerherg.ergerg"
# m =str.maketrans('aeiou','12345')
# new_v =v.translate(m)
# print(new_v)
# 输出:21w2s1d1sd1sgffdgs2rg2rh2rg.2rg2rg # 做分割:↓
# 用法区别:partition 包含分割的元素 split不包含分割的元素
# test ='dsfsdfsdrewrdddfsdsfds'
# v =test.partition('s')
# print(v)
# 输出:('d', 's', 'fsdfsdrewrdddfsdsfds')
# v =test.rpartition('sf')
# print(v)
# 输出:('dsfsdfsdrewrdddfsd', 'sf', 'ds')
# split的弊端是不能提取 使字符串分割的值 比如下面的's'
# test ='qwesxcxzsadsadasdasf'
# v = test.split('s')
# print(v)
# 输出:['qwe', 'xcxz', 'ad', 'ada', 'da', 'f']
# v = test.split('s',3)
# print(v)
# 输出:['qwe', 'xcxz', 'ad', 'adasdasf'] # 分割,只能根据True,False:是否保留换行
# test ='sadasdaewq\nasdsasldksal\n'
# v = test.splitlines(True)
# print(v) # 替换:
# test ='alexalexalex'
# v = test.replace('ex','bbb')
# print(v)
# 输出:albbbalbbbalbbb
# v =test. replace('ex','bbb',2)
# print(v) ↓
# 输出:albbbalbbbalex 替换前2个字符 # 以xxxx开头,以xx结尾
# test = 'backhand1.1.1'
# v =test.startswith('ba')
# print(v)
# v =test.endswith('1')
# print(v) # 字符串一旦创建就不可修改
# 一旦修改或者拼接,都会造成重新生成字符串
# name ='sunpengfei'
# age = '18'
# info = name + age
# print(info) # 索引,下标,获取字符串中的某一个字符
# test ='alexjk'
# v = test[3]
# print(v)
# 输出:x # 切片
# v = test[0:-1] #0=< <-1
# print(v)
# 输出alexj # len获取当前字符串中由多少个字符组成
# test ='alexad'
# v =len(test)
# print(v)
# 输出:6 # 注意:
# v =len('asdasd')
# v ='_'.join('dasdasdas')
# print(v) # li = [11,22,33,44,55,'sad']
# len('sadsadasdasd')
# len(li) # test ='妹子有本事你到我床上来'
# index = 0
# while index< len(test):
# v = test[index]
# print(v)
# index +=1
# print('=====================')
# for循环: # for 变量名 in 字符:串
# for i in test:
#print(i) # test ='妹子有本事你到我床上来'
# for item in test:
# print(item)
# break # for item in test:
# continue
# print(item) # range:帮助创建连续的数字,通过设置步长来指定不连续
# v = range(0,100,5)
# # print(v)
# for item in v:
# print(item) # test =input('>>>')
# print(test)
# l =len(test)
# print(l)
#
# r = range(0,l)
# for item in r:
# print(item, test[item])
# 总结上面的:
# test = input('>>>')
# for item in range(0,len(test)):
# print(item,test[item]) s = ' ' while True:
v1 = input('>>>')
v2 = input('>>>')
v3 = input('>>>')
template = '{0}\t{1}\t{2}\n'
v = template.format(v1, v2, v3)
s = s + v
break
print(s.expandtabs(20))

str 操作方法的更多相关文章

  1. python之字符串str操作方法

    str.upper() (全部大写) str.lower() (全部小写) str.startswith() (以什么开头) str.endswith() (以什么结尾) str.count() (统 ...

  2. str操作方法

    s = 'dsj,fhk,je,f' # s1 = s.split(',') # print(s1) s = 'aleX leNb' s1 = s.strip() print(s1) s2 = s[2 ...

  3. day02_20190106 基础数据类型 编码 运算符

    一.格式化输出 name = input('请输入姓名') age = input('请输入年龄') hobby = input('请输入爱好') job = input('请输入你的工作') # m ...

  4. week3_notebooke1

    今日内容:编码集合深浅cpoy文件操作函数初始函数函数的返回值函数的传参 初识: # == 数值比较 # is 比较的是内存地址 # id 测试的是内存地址 # 小数据池 str int # int: ...

  5. python之目录

    一.python基础 ​ python之字符串str操作方法 ​ python之int (整型) ​ python之bool (布尔值) ​ python之str (字符型) ​ python之ran ...

  6. Python语言系列-02-基础数据类型

    格式化输出 #!/usr/bin/env python3 # author:Alnk(李成果) # 百分号% 格式化输出 name = input('姓名:') age = input('年龄:') ...

  7. python之路day03--数据类型分析,转换,索引切片,str常用操作方法

    数据类型整体分析 int :用于计算bool:True False 用户判断str:少量数据的存储 list:列表 储存大量数据 上亿数据[1,2,3,'zzy',[aa]] 元组:只读列表(1,23 ...

  8. 003_python的str切片,str常用操作方法,for循环,集合,深浅copy

    基础数据类型 基础数据类型,有7种类型,存在即合理. 1.int 整数 主要是做运算的 .比如加减乘除,幂,取余  + - * / ** %... 2.bool布尔值 判断真假以及作为条件变量 3.s ...

  9. Python 中的字符串(str)、字典(dict)详解及操作方法

    一.字符串 在python中字符串是一种重要数据类型.其他数据类型分别为: 数字-number -------- int.long.float.complex这几种 字符串-string ------ ...

随机推荐

  1. ssh远程执行命令使用明文密码

    经过不懈的搜索终于找到ssh远程执行命令使用明文密码使用sshpass. 例子: sshpass -p "sequoiadb" ssh root@localhost "l ...

  2. Spring Bean的装配

    Bean 的装配,即Bean对象的创建.容器根据代码要求创建Bean对象后再传递给代码的过程,称为Bean的装配. 一.默认分的装配方式 默认的装配的方式调用Bean类的构造方法 二.动态工厂Bean ...

  3. docker,mysql,Navicat

    Navicat破解网址  https://www.jianshu.com/p/5f693b4c9468 docker pull mysql docker run -d -p 3306:3306 --n ...

  4. CSS3 -- FlexBox(弹性盒子)

    盒子模型 CSS中有一种基础设计模式叫盒模型,盒模型定义了Web页面中的元素如何来解析. 在盒模型中主要包括width.height.border.background.padding和margin这 ...

  5. 【转】oracle远程导入数据库

    源地址:http://blog.chinaunix.net/uid-20980141-id-447996.html

  6. uoj#422. 【集训队作业2018】小Z的礼物(MIn-Max容斥+插头dp)

    题面 传送门 题解 好迷-- 很明显它让我们求的是\(Max(S)\),我们用\(Min-Max\)容斥,因为\(Min(S)\)是很好求的,只要用方案数除以总方案数算出概率,再求出倒数就是期望了 然 ...

  7. [51nod1222] 最小公倍数计数(莫比乌斯反演)

    题面 传送门 题解 我此生可能注定要和反演过不去了--死都看不出来为啥它会突然繁衍反演起来啊-- 设\(f(n)=\sum_{i=1}^n\sum_{j=1}^n[{ij\over\gcd(i,j)} ...

  8. 洛谷P4137 Rmq Problem / mex(莫队)

    题目描述 有一个长度为n的数组{a1,a2,…,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. 输入输出格式 输入格式: 第一行n,m. 第二行为n个数. 从第三行开始,每行一个询问l, ...

  9. java 实现导出Excel文件

    java 实现导出Excel(java生成 excel 并导出文件) 经常有有一些数据需要导出成   excel  格式 ,所以就需要实现啦 开始: 1.加入jar poi-3.6-20091214. ...

  10. KindEditor的参考文献

    转自:http://www.cnblogs.com/wupeiqi/articles/6307554.html