#!coding=utf-8#'''
eval(str)
将字符串当成有效的表达式,并返回结果,相当与int
'''
num1=eval('123')print(num1)print(type(num1))print(eval('12-3'))print(eval('-123'))#len(str)#返回字符串的长度print(len('Tom is a good man!'))print(len('Tom is 一 good man!'))'''
lower(str):将str中的字母转换成小写字母
'''
str20='Tom is a good man'
str21=str20.lower()print('str20=%s,str21=%s'%(str20,str21))#upper()转换字符串中的小写为大写字母
str21='TOM is a good man'print('的大写是:',str21.upper())print('我是')#swapcase():小写转成大写,大写转成小写
str22='Tom Is A Good Man'print(str22.swapcase())#capitalize:首字母大写,其他小写
str21='TOM is a good man'print(str21.capitalize())#title()每个单词的首字母大写,其他小写
str21='TOM Is A Good Man'print(str21.title())#center(width,fillchar):长度width,字符居中,其余的填充fillchar字符
str21='TOM Is A Good Man'print(str21.center(30,"-"))#ljust(width,[fillchar]):长度width,字符居左,其余的填充fillchar字符
str21='TOM Is A Good Man'print(str21.ljust(30,'-'))#rjust(width,[fillchar]):长度width,字符居右,其余的填充fillchar字符
str21='TOM Is A Good Man'print(str21.rjust(30,'-'))#zfill(width):长度width,字符居右,其余的填充0
str21='TOM Is A Good Man'print(str21.zfill(30))#count(str1,[stat],[end]):找个数
str21='TOM Is A Good Good Man'print(str21.count('o'))#4个print(str21.count('oo'))#2个print(str21.count('Good'))#2个#find(str1,[stat],[end]):找位置,没有返回-1
str21='TOM Is A Good Good Man'print(str21.find('oo'))#10#rfind(str1,[stat],[end]):找位置,没有返回-1
str21='TOM Is A Good Good Man'print(str21.rfind('oo'))#15#index(str1,[stat],[end]):找位置,没有返回异常
str21='TOM Is A Good Good Man'print(str21.index('oo'))#10#rindex(str1,[stat],[end]):找位置,没有返回异常
str21='TOM Is A Good Good Man'print(str21.rindex('oo'))#15#lstrip(fillchar):截掉左侧的fillchar,默认为空格
str21='****TOM Is A Good Good Man'print(str21.lstrip('*'))#rstrip(fillchar):截掉右侧的fillchar,默认为空格
str21='****TOM Is A Good Good Man 'print(str21.rstrip())#lstrip(fillchar):截掉两侧的fillchar,默认为空格
str21='****TOM Is* A Good Good Man****'print(str21.strip('*'))print(str21.strip())
字符串方法#!coding=utf-8#'''eval(str)将字符串当成有效的表达式,并返回结果,相当与int'''num1=eval('123')print(num1)print(type(num1))print(eval('12-3'))print(eval('-123'))#len(str)#返回字符串的长度print(len('Tom is a good ma...