1、capitalize 首字母大写
test = "alex"
#首字母大写
v = test.capitalize()
print(v)
结果:
Alex
2、大小写转换
2.1)大写字母转换成小写
lower
casefold(很多未知的都能变小写,一般用不到)

3、center
功能:设置这个字符占的宽度
#def center(width,fillchar=None) 遇到=,可以带,可以不带
#设置宽度,并将内容居中
# width 20 代表总长度
# * 空白位置填充,只能带一个字符,也可以不填写
test = "ALEX"
v1 = test.center(20,"*")
print(v1)
类似:
ljust: 放左边
rjust:放右边

4、count
功能: 判断这个字母出现的次数
#def count(self, sub, start=None, end=None)
#start 表示从第几位开始
#end 表示找到第几位结束
#默认是所有的,从第一位开始找
test = "louisalexfix"
v1 = test.count('l')
print(v1)
test = "loexuiexlexfix"
v1 = test.count('ex',5,10)
print(v1)
4、endswith
功能:以()里的结尾, 可以用于条件判断

5、startswith
功能: 以()里的开头,可以用于条件判断

6、find
功能: 从前往后查找,找到第一个,获取其位置,之后的就不查找咯。不能找到显示-1
test = "alexalexfiex"
v1 = test.find('ex')
print(v1)
结果: 2

7、format
功能: 格式化,将字符串上的占位符,替换成指定的值


--format_map
name = input("please input name:")
age = input("please input age: ")
tem="I am {0},age {1}"
v1 = tem.format(name,age)
print(v1)
8:判断是否是啥 ---可以用于条件判断
8.1)isalum
字符串里只能出现字母和数字

8.2) isalpha
判断是否为字母、汉子
test = "我"
v1 = test.isalpha()
print(v1)

8.3) isdigit
功能:判断当前是不是数字

相似的:
isnumeric 支持中文的数字,比如二
isdecimal 支持特殊的字符2
案例:

注意: 以后用的最多的,还是isdecimal比较多
8.4) isidentifier
功能:判断是否有一个标识符,需要满足有字母,数字,下划线
以数字开头的,都为false


8.5) isspace
功能:是否为空格

8.6) islower lower
功能: 判断是否全部为小写字母和转换为小写

8.7) isupper supper
功能:判断是否全部为大写,和转换给大写

9: expandtabs
功能:分隔,对齐 expandtabs(n),以n个为一组,如果遇到\t, 就以空格补全
test="abcdeffd\tdif\tdi\t"
v1 = test.expandtabs(6)
print(v1)
原理: abcdef fd\t dif\t di\t
遇到\t,把不够的用空格标识,例如这里是6,然后fd只占有2个,遇到\t咯,那么就需要补4个空格,依次类推

10 join -------非常重要
功能:#将字符串中的每一个元素按照指定的分隔符分开
test = "你是风儿我是沙"
v1 = "_".join(test)
print(v1)
11、lstrip rstrip strip
功能:
1)去掉空白
2)去掉\n,\t特殊的字符
3)去掉指定的字符,以先最多匹配去除,依次去找
lstrip: 取出左边的
rstrip: 取出右边的
strip: 取出左右两边


12、partition
功能: 以某个()东西为分隔,只能分隔成三分
split:
匹配到的字符拿不到
可以指定分隔的个数
默认是全部

13、字符串替换replace

重点:
join 连接
split(split,lspit,rspit)分隔
find (查找)
strip(lstrip,rstrip,strip)去除
upper 大写
lower 小写
replace 替换
#########################灰魔法#######################
1、获取字符串里的某一个字符,索引从0开始

2、切片, 左边 <=x < 右边

3、len
test = "我来自云南省昆明市"
index = 0
while index < len(test):
t = test[index]
print(t)
index += 1
test = "我来自云南省昆明市"
#
for index in test:
print(index)
4、循环(for,while)
test = "thisidfswork"
v1 = test.split('s')
for i in v1:
print(i)

5、range
功能:帮助创建连续的数字,默认从0开始,也可以创建不连续的数字
在python2中会直接创建,在python3中,要用循环,才会打印出来


test = input("please input: ")
len = len(test)
for item in range(0,len):
print(item,test[item])
案例:打印一个表格
test = " "
while True:
t = input("please input caozhuo: ")
if t == "y":
name = input("please input name: ")
pwd = input("please input passwd: ")
email = input("please input email adddress: ")
temp = "{0}\t{1}\t{2}\n"
v1 = temp.format(name,pwd,email)
test = test + v1
elif t == "q":
break
else:
pass
print(test.expandtabs(20))
