day11


# expandtabs,断句

test="12345678 9"
v=test.expandtabs(6)
print(v) #12345678 9


test="username email password laiying laiying.com 123 laiying laiying.com 123 laiying laiying.com 123"
v=test.expandtabs(20)
print(v)

# username email password
# laiying laiying.com 123
# laiying laiying.com 123
# laiying laiying.com 123


test="asdf"
v=test.isalpha()
print(v) # True 判断是否是字母

test="123"
v1=test.isdecimal() # 阿拉伯数字
v2=test.isdigit() #特殊数字
v3=test.isnumeric()
print(v1,v2,v3) #当前输入是否为数字 汉字数字

a="def"
v=a.isidentifier()
print(v) # 是否是字符串

islower #是否都是小写


test="oiuasdkj"
v=test.isprintable()
print(v) # 是否存在不可显示的字符 例如 制表符 换行


test="oiuasdkj"
v=test.ispace()
print(v) # 判断是否全部是空格


test="Return True if all cased charactes in S are uppercase and there is"
v1=test.istitle() #判断是否是标题
v2=test.title() #转换为标题
print(v1,v2)


test="你是风儿我是沙"
print(test)
t=" "
v=t.join(test)
print(v) #你 是 风 儿 我 是 沙 将字符串中的的每一个元素按照指定分隔符进行拼凑 很重要 要记住

 

test="alex"
v=test.ljust(20,"*")
print(v) #alex****************

r.just

test="alex"
v=test.zfill(20)
print(v) #左边填充为0


islower #判断是否是小写
lower #变成小写

isupper #判断是否是大写
upper #变成大写

test="alex"
test.lstrip() #去除左右空白 去除
test.rstrip()
test.strip()


test="xalex"
v=test.lstrip("x")
ptint(v) #去掉前面的x 移除指定字符 优先最多匹配


v="asdffjhhjmmmljn"
m=str.maketrans("aeiou","12345")
new_v=v.translate(m)
print(new_v) #把对应的替换


test="testasdsddfg"
v1=test.partition("s") # ('te', 's', 'tasdsddfg')
v2=tese.rpartition("s") #从后面开始分割('testasd', 's', 'ddfg') ['te', 'ta', 'd', 'ddfg'] ['te', 'ta', 'd', 'ddfg']
v3=test.split("s") # ['te', 'ta', 'd', 'ddfg'] 还可以指定个数
v4=test.rsplit("s") # ['te', 'ta', 'd', 'ddfg']
print(v1,v2,v3,v4)


正则表达式也可以进行分割 可以指定是否想要分割的元素


splitlines 只能根据换行进行分割 true false 用来指定是否保留换行符


test="backend 1.1.1.1"
v=test.startswith("a") #以什么开头和以什么结尾
v=test.endswith("a")
print(v)


swapcase() #大小写转换



必须记住 join split find strip(去除) upper lower


test="alex"
v=test[0]
print(v) #索引 下标获取某一个字

 

v=test[0:1] #索引范围


len(test) #获取字符数目 Python3 中是酱紫


test="郑健文妹子有种冲我来"
index=0
while index<len(test):
v=test[index]
print(v)
index+=1
print("end")

for zjw in test:
print(zjw)


for循环
for 变量名 in 字符串


len
for循环
索引 # 在其他数据类型中也能用
切片

test="郑健文妹子有种冲我来"
for item in test:
print(item)

continue break 在for循环中也适用


v=range(0,100,5) #创建连续的数字 也可以设置步长
print(v) # range(0,100)

for item in v:
print(item)




test=input("")
for item in test:
print(item)

将文件对应的索引打印出来

v=range(0,len(test))
for item in v:
print(item,test[item])

总共记住十个

name="郑健文"
age="19"
info=name+age
print(info) 字符串一旦创建或拼接 都会重新生成字符串(重新开辟空间)



test="alexalexalex"
v=test.replace("ex","bb",1) #只替换第一个 可改变参数 这个也要会

print(v)

2018-07-27

原文地址:https://www.cnblogs.com/jiangjunfeng/p/9379049.html