2.14 day11

  1 #day11
  2 
  3 
  4 
  5 
  6 #expandtabs 断句20 如果占用20个字就不用填充 反之可用/t来填充
  7 test = "username\temail\tpassword\nlaiying\[email protected]\t123\nlaiying\[email protected]\t123\nlaiying\[email protected]\t123\n"
  8 
  9 v = test.expandtabs(20)
 10 
 11 print(v)
 12 
 13 >>> ================================ RESTART ================================
 14 >>> 
 15 username            email               password
 16 laiying             [email protected]       123
 17 laiying             [email protected]       123
 18 laiying             [email protected]       123
 19 
 20 
 21 #只有字母(包括汉字)为真
 22 test ="asdqwdwq2fefs"
 23 v = test.isalpha()
 24 print(v)
 25 
 26 #当前输入是否是数字  文件操作
 27 test = "123二"
 28 v1 = test.isdecimal        #十进制小数
 29 v2 = test.isdigit        #包含特殊符号
 30 v3 = test.isnumeric        #中文也支持
 31 print(v1,v2)
 32 
 33 
 34 # 判断是否符合字母,数字,下划线,标识符 def class
 35 # !需确认
 36 a = “123 37 v = a.isidentifier
 38 print(v)
 39 
 40 #是否包含不可见的字符(命令)
 41 #\t 制表符
 42 #\n 换行
 43 test = "daiodfe\r \t woifjweo"
 44 v = test.isprintable()
 45 print(v)
 46 >>> 
 47 False
 48 
 49 
 50 
 51 #判断是否全是空格
 52 test = "djqhwo dji"
 53 v = test.isspace()
 54 print(v)
 55 
 56 #判断是否为标题(所有字母均为大写)
 57 test = "Return Ture if all cased characters in S are uppercase and thereis"
 58 v = test.title()#转换为标题
 59 v2 = test.istitle()
 60 print(v)
 61 print(v2)
 62 
 63 
 64 
 65 #***非常重要***将字符串中的每一个元素按照指定分割符进行拼接
 66 #!需确认 day_11_04_14'44"
 67 test = "今天情人节,晚上跟嘟嘟打游戏"
 68 print(test)
 69 #t = '_'
 70 v = '*'.join(test)
 71 print(v)
 72 
 73 
 74 
 75 #左边或者右边插入* 
 76 #!寻找center对比
 77 test = "Phyllis"
 78 v = test.rjust(20,"*")
 79 v2 = test.ljust(20,"*")
 80 v3 = test.center(20,"*")
 81 v4 = test.zfill(20)#用0填充
 82 print(v)
 83 print(v2)
 84 print(v3)
 85 print(v4)
 86 #>>>
 87 *************Phyllis
 88 Phyllis*************
 89 ******Phyllis*******
 90 0000000000000Phyllis
 91 
 92 
 93 
 94 
 95 #移除指定字符串
 96 #优先最多匹配
 97 test = 'sadqwd'
 98 v = test.rstrip('sads')#strip vt. 剥夺;剥去;脱去衣服
 99 print (v)
100 
101 
102 #对应关系进行一一对换
103 test = 'ehqfuiewh'
104 test2 = '123456789'
105 v = 'ehqfuiewhhdiquwhdiehqfuiewh'
106 m = str.maketrans('ehqfuiewh','123456789')
107 new_v = v.translate(m)
108 print(new_v)
109 >>>
110 7934567899d63589d6793456789
111 
112 
113 test = 'testasdsddfg'
114 v  = test.partition('s')#从第一个s为中心,把字符串分割成为三份(包含分割s)
115 v2 = test.rpartition('s')#从右边第一个s为中心,把字符串分割为三份(包含分割s)
116 v3 = test.split('s',2)#左数前两个s为分割点,分割成2+1份(不包含分割s)
117 v4 = test.rsplit('s',2)#右数前两个s为分割点,分割成2+1份((包含分割s)
118 print(v,v2,v3,v4)
119 
120 #>>>('te', 's', 'tasdsddfg') ('testasd', 's', 'ddfg') ['te', 'ta', 'dsddfg'] ['testa', 'd', 'ddfg']
121 #正则表达式
122 #是否想要分割的元素
123 
124 
125 #分割,只能根据,true,false;是否保留换行
126 test = "asdhwei\nuo\nfhwieu"
127 v  = test.splitlines(False)
128 v2 = test.splitlines(True)#true显示\n
129 print(v,v2)
130 
131 #判断是否以**开头/结尾
132 test = "backend 1.1.1.1"
133 v1 = test.startswith("a")
134 v2 = test.endswith('1')
135 print(v1,v2)
136 #>>>
137 False True
138 
139 
140 #大小写相互转换
141 test = "Phyllis"
142 v = test.swapcase()
143 print(v)
144 #>>>
145 pHYLLIS

#day11



#expandtabs 断句20 如果占用20个字就不用填充 反之可用/t来填充test = "username\temail\tpassword\nlaiying\[email protected]\t123\nlaiying\[email protected]\t123\nlaiying\[email protected]\t123\n"
v = test.expandtabs(20)
print(v)
>>> ================================ RESTART ================================>>> username            email               passwordlaiying             [email protected]       123laiying             [email protected]       123laiying             [email protected]       123

#只有字母(包括汉字)为真test ="asdqwdwq2fefs"v = test.isalpha()print(v)
#当前输入是否是数字  文件操作test = "123二"v1 = test.isdecimal#十进制小数v2 = test.isdigit#包含特殊符号v3 = test.isnumeric#中文也支持print(v1,v2)

# 判断是否符合字母,数字,下划线,标识符 def class# !需确认a = “123”v = a.isidentifierprint(v)
#是否包含不可见的字符(命令)#\t 制表符#\n 换行test = "daiodfe\r \t woifjweo"v = test.isprintable()print(v)>>> False


#判断是否全是空格test = "djqhwo dji"v = test.isspace()print(v)
#判断是否为标题(所有字母均为大写)test = "Return Ture if all cased characters in S are uppercase and thereis"v = test.title()#转换为标题v2 = test.istitle()print(v)print(v2)


#***非常重要***将字符串中的每一个元素按照指定分割符进行拼接#!需确认 day_11_04_14'44"test = "今天情人节,晚上跟嘟嘟打游戏"print(test)#t = '_'v = '*'.join(test)print(v)


#左边或者右边插入* #!寻找center对比test = "Phyllis"v = test.rjust(20,"*")v2 = test.ljust(20,"*")v3 = test.center(20,"*")v4 = test.zfill(20)#用0填充print(v)print(v2)print(v3)print(v4)#>>>*************PhyllisPhyllis*******************Phyllis*******0000000000000Phyllis



#移除指定字符串#优先最多匹配test = 'sadqwd'v = test.rstrip('sads')#strip vt. 剥夺;剥去;脱去衣服print (v)

#对应关系进行一一对换test = 'ehqfuiewh'test2 = '123456789'v = 'ehqfuiewhhdiquwhdiehqfuiewh'm = str.maketrans('ehqfuiewh','123456789')new_v = v.translate(m)print(new_v)>>>7934567899d63589d6793456789

test = 'testasdsddfg'v  = test.partition('s')#从第一个s为中心,把字符串分割成为三份(包含分割s)v2 = test.rpartition('s')#从右边第一个s为中心,把字符串分割为三份(包含分割s)v3 = test.split('s',2)#左数前两个s为分割点,分割成2+1份(不包含分割s)v4 = test.rsplit('s',2)#右数前两个s为分割点,分割成2+1份((包含分割s)print(v,v2,v3,v4)
#>>>('te', 's', 'tasdsddfg') ('testasd', 's', 'ddfg') ['te', 'ta', 'dsddfg'] ['testa', 'd', 'ddfg']#正则表达式#是否想要分割的元素

#分割,只能根据,true,false;是否保留换行test = "asdhwei\nuo\nfhwieu"v  = test.splitlines(False)v2 = test.splitlines(True)#true显示\nprint(v,v2)
#判断是否以**开头/结尾test = "backend 1.1.1.1"v1 = test.startswith("a")v2 = test.endswith('1')print(v1,v2)#>>>False True

#大小写相互转换test = "Phyllis"v = test.swapcase()print(v)#>>>pHYLLIS


猜你喜欢

转载自www.cnblogs.com/phyllissRyo/p/10381422.html