字符串

判断以什么开头或以什么结尾

#startswith(self, prefix, start=None, end=None
name = "alex"
v = name.startswith("a")  #开头(后面能带范围)
v = name.endwith("ex",1,3)    #结尾   (后面能带范围)
print(v)

从开始往后找,找到第一个之后 获取地址

test = "alexalexalex"
v = test.find("ex")  #获取第一个的位置(可以添加范围)
print(v)

格式化,将一个字符串中的占位符替换成指定的值

test = " i am {name}, age {a}"
v = test.format(name="arman",a = 21)
#test = " i am {0}, age {1}"
#v = test.format("arman",21)  
print(v)
>> i am arman, age 21

判断字符串中时候只包含字母和数字

test = "sfsfsfsw435345__"
v = test.isalnum()      #test.isalpha() 只包含字母
print(v)                #test.isdecimal() and test.isdigit() and {更牛逼}test.isnumeric() 只包含数字  
>>False

expandtabs(能制表),首先进行断句

test ="username\temail\tpassword\narman\tarman@163.com\t1234qe\narman\tarman@163.com\t1234qe\narman\tarman@163.com\t1234qe\n"
v = test.expandtabs(20)   #20指每20个断句,如果有\t,\t就代替剩余位置
print(v)
>>> # 比如 \t前面有13个 那\t就充当后面7个位置

username    email           password
arman       arman@163.com   1234qe
arman       arman@163.com   1234qe
arman       arman@163.com   1234qe

 是否存在不可显示的字符(\t,\n.....)

test = "sdjvs\tzcvhv"      #里边含有\t
v = test.isprintable()
print(v)
>>> False

判断是否全是空格(不包括空)

test = "     "
v = test.isspace()
print(v)

把文本转换成标题,(每个单词首字母变大写)

test = "i am a student,i love learning"
v = test.title()
print(v)

判断是否是标题

test = "i am a student,i love learning"
v = test.istitle()
print(v)

 

posted @ 2018-10-03 17:09  NewBird53  阅读(132)  评论(0)    收藏  举报