python乘号的字符代码_python之字符串函数

1.  endswith()  startswith()

0a59822ee8992dd061c935d92431baa9fb5.jpg

ff51916411011411805b8d6187a01e05596.jpg

1 #以什么什么结尾

2 #以什么什么开始

3 test = "alex"

4 v = test.endswith('ex')5 v = test.startswith('ex')6 print(v)

View Code

2. expandtabs()

b8359df364f1e8becb9eb2725f6e73120c7.jpg

067a378b33f33720cd7460dc01bc498612a.jpg

1 test = "1\t2345678\t9"

2 v = test.expandtabs(6)3 print(v,len(v))

View Code

3. find()

2713a121dd37c9e87865e168818abdbaa8f.jpg

0dc71031bf7c720d89a509ee60760f7b525.jpg

1 #从开始往后找,找到第一个之后,获取其未知

2 #> 或 >=

3 test = "alexalex"

4 #未找到 -1

5 v = test.find('e')6 print(v)

View Code

4.  index()

2ad0e8f1b8e64428e35260fc095ddc6d3a2.jpg

32d664ad1b8ace3ce4966be38621480b2f2.jpg

1 #index找不到,报错 忽略

2 test = "alexalex"

3 v = test.index('a')4 print(v)

View Code

5. format()  format_map()

ed2de74fc3fcf9b1f53c0d8c9f838c9262c.jpg

9080d5e267283740640901e5a8a5f3dd861.jpg

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

2 test = 'i am {name}, age {a}'

3 print(test)4 v = test.format(name='alex',a=19)5 print(v)6

7 test = 'i am {0}, age {1}'

8 print(test)9 v = test.format('alex',19)10 print(v)11

12 #格式化,传入的值 {"name": 'alex', "a": 19}

13 test = 'i am {name}, age {a}'

14 v1 = test.format(name='df',a=10)15 print(v1)16 v2 = test.format_map({"name": 'alex', "a": 19})17 print(v2)

View Code

6. isalnum()

9662c553d49ad938d0e25081a152e6f7a89.jpg

89eb1f4b954b1a928964d8f6fac42ba974e.jpg

1 #字符串中是否只包含 字母和数字

2 test = "er;"

3 v =test.isalnum()4 print(v)

View Code

7.capitalize() 首字母大写

4a9d639a037f6c88d2286e00c6e2e8968f2.jpg

3ac3314d14b86d3d0f075ddc816e18fdbbb.jpg

1 test = "sqy"

2 v =test.capitalize()3 print(v)

View Code

8. casefold()  lower() 所有变小写,casefold更牛逼,很多未知的对相应变小写

333a9af9e6e54e6a07d8969e4c94ded8506.jpg

156eac82032a8fbbfc383bea4e0bc647b17.jpg

1 test = "sqy"

2 v1 =test.casefold()3 print(v1)4 v2 =test.lower()5 print(v2)

View Code

9. center() 置宽度,并将内容居中

24696647375943166ba2587582c62c9a544.jpg

9283c73133d2e47f84364be49b3c47d0ff2.jpg

1 # 20代指总长度2 # *空白未知填充,一个字符,可有可无3 test = "sqy"

4 v = test.center(20,"中")5 print(v)

View Code

10.  ljust() rjust() zfill()

b78ac144c9665d630703c7ed92050ee26e4.jpg

e248b3e5a5862bc955dd422794c9a317421.jpg

1 # test = "alex"

2 # v = test.ljust(20,"*")3 # print(v)4

5 # test = "alex"

6 # v = test.rjust(20,"*")7 # print(v)8

9 # test = "alex"

10 # v = test.zfill(20)11 # print(v)

View Code

11. count() 去字符串中寻找,寻找子序列的出现次数

33e01a508b4c25118e1331bd90f4c196072.jpg

9f7867fcecc3b253506f9ab6db56854e853.jpg

1 test = "aLexalexr"

2 v = test.count('ex')3 print(v)4

5 test = "aLexalexr"

6 v = test.count('ex',5,6)7 print(v)

View Code

12. isalpha() 是否是字母,汉子

90abaead2ccb5bb5993d0c96257088f31c8.jpg

825d757ea4f9ed8e8fede046a99d81eb066.jpg

1 test = "as大多数df"

2 v =test.isalpha()3 print(v)

View Code

13. isdecimal()  isdigit() isnumeric()  当前输入是否是数字

7f707649f1fde094c07a0493e8dd824a537.jpg

69afd3bb5b04bca6467c725050816fb077e.jpg

1 test = "②" # 1,②,儿2 v1 =test.isdecimal()3 v2 =test.isdigit()4 v3 =test.isnumeric()5 print(v1,v2,v3)

View Code

14.isprintable() 是否存在不可显示的字符

d7da0f15061ec0bf72a1ff7ef9c9555560f.jpg

c0034b9936ab3aad04b87f9ead7fcacd738.jpg

1 # \t 制表符2 # \n 换行3 test = "gdds\tfdsfd"

4 v =test.isprintable()5 print(v)

View Code

15. isspace()  判断是否全部是空格

1a2887a4b150d16867c419facf81a5745df.jpg

d617f68631a3906764da81be573b0a71e10.jpg

1 test = " ass"

2 v =test.isspace()3 print(v)

View Code

16.  istitle() title() 判断是否是标题

e9eed0d12c5ef4fa3b06bb4783def655d14.jpg

800bcf0c1a43d21112c9c241ae5657fc1dc.jpg

1 test = "Return True if all cased characters in S are uppercase and there is"

2 v1 =test.istitle()3 print(v1)4 v2 =test.title()5 print(v2)6 v3 =v2.istitle()7 print(v3)

View Code

17. join() 将字符串中的每一个元素按照指定分隔符进行拼接

f011dc9366bda1b3976428a520e61691f1b.jpg

15eb5326f329b23894a625247e054d291e2.jpg

1 test = "你是风儿我是沙"

2 print(test)3 t = ' '

4 v = "_".join(test)5 print(v)

View Code

18.  islower()lower() isupper() upper()

0d64c34cf26004f97efff7bda321a07bde3.jpg

087855fd3a57d7a13c1620a85437119be60.jpg

1 test = "Alex"

2 v1 =test.islower()3 v2 =test.lower()4 print(v1, v2)5

6 v1 =test.isupper()7 v2 =test.upper()8 print(v1,v2)

View Code

19. lstrip()  rstrip() strip() 移除指定字符串 有限最多匹配

f15101cabc9d12da0f1c7cebe92400a5a1d.jpg

a89afa4deada2d653aea3c1509ee002c85f.jpg

1 test = "\nxas12xa\n\txax1221axa "

2 v = test.lstrip('xa')3 v = test.rstrip('9lexxexa')4 v = test.strip('xa')5 print(v)6

7 test.lstrip()8 test.rstrip()9 test.strip()10 # 去除左右空白11 v =test.lstrip()12 v =test.rstrip()13 v =test.strip()14 print(v)15 print(test)16 # 去除\t \n17 v =test.lstrip()18 v =test.rstrip()19 v =test.strip()20 print(v)

View Code

20. maketrans()  translate()  对应关系替换

e35cfbad458fbd3060a63f09d77d720a85d.jpg

f0de2ce479b584ee18c0aa9fa3a5ce803ca.jpg

1 v = "asidufkasd;fiuadkf;adfkjalsdjf"

2 m = str.maketrans("aeiou", "12345")3 new_v =v.translate(m)4 print(new_v)

View Code

21. partition()  rpartition() 分割为三部分

64bf146bd1d85738ad7edd7b549e7f20d60.jpg

146bb81098659ff421a6f6652dc93405a8b.jpg

1 test = "testasdsddfg"

2 v = test.partition('s')3 print(v)4 v = test.rpartition('s')5 print(v)

View Code

22. split() rsplit()  splitlines()

22a1d45713aa87e41475ee13033f46fedff.jpg

2c3a95a60520b6a2a40254ab0f7f1617fc6.jpg

1 test = "sqys"

2 v = test.split('s',2)3 print(v)4 v =test.rsplit()5 print(v)6

7

8 # 23 分割,只能根据,true,false:是否保留换行9 # test = "asdfadfasdf\nasdfasdf\nadfasdf"

10 # v =test.splitlines(False)11 # print(v)

View Code

23. swapcase() 大小写转换

46b050ecf3bab4f58a8a9635cc1d31704d3.jpg

890de473fb66f6c1e96d5cdc09a58f8c1c0.jpg

1 test = "aLex"

2 v =test.swapcase()3 print(v)

View Code

24. isidentifier() 字母,数字,下划线 : 标识符 def class

5ea2c80686e3afe497a67575dbf71ea67de.jpg

601fe37669a51e78ec859a64ac8ccf86db7.jpg

1 a = "de12_f"

2 v =a.isidentifier()3 print(v)

View Code

25.replace()  将指定字符串替换为指定字符串

3bf4a110906f84b052b14b41b33d9ca6de5.jpg

20be6352ddd1bfd4d414a8ae0c703e19cd4.jpg

1 test = "alexalexalex"

2 v = test.replace("ex",'bbb')3 print(v)4 v = test.replace("ex",'bbb',2)5 print(v)

View Code

26.灰魔法

一、for循环

c5c23a573b648ffbdcfccbded0f9770bea6.jpg

488b9d3e884c1c023a9cac408842393a0b3.jpg

1 test = "返回到合肥东方红刚才修改"

2 #for 变量名 in 字符串:

3 #变量名

4 #break

5 #continue

6

7

8 index =09 while index

13 index += 1

14 print('=======')15

16 for zjw intest:17 print(zjw)18

19 test = "好方法个地方个地方刚发的"

20 for item intest:21 print(item)22 break

23

24 for item intest:25 continue

26 print(item)

View Code

二、索引,下标,获取字符串中的某一个字符

8aebbbe1618469ec9f21093b222f09ff3c8.jpg

03ef4c870ae4906ba4c541adc5c730921ba.jpg

1 test = "好方法个地方个地方刚发的"

2 v = test[3]3 print(v)

View Code

三、切片

8c1c8788eb2aa09150c6ad73323b6a38008.jpg

9721f859e9d8ed2856eff8c62084a5f6283.jpg

1 test = "好方法个地方个地方刚发的"

2 v = test[0:10] #0=< <1

3 print(v)

View Code

四、获取长度

7d45f74e15c2c8c279a6428a0555745430e.jpg

e97ea3301b54447d822bce24e8ffd1517f8.jpg

1 #Python3: len获取当前字符串中由几个字符组成

2 test = "好方法个地方个地方刚发的"

3 v =len(test)4 print(v)

View Code

27. range()  获取连续或不连续的数字

aede1c5134dc99ba96d2c2bc3911ddbe022.jpg

4e9e495831f14c777a8831866e207f8ec20.jpg

1 #Python2中直接创建在内容中

2 #python3中只有for循环时,才一个一个创建

3 v = range(10)4 v = range(3,10)5 v = range(1,10,2)6 #帮助创建连续的数字,通过设置步长来指定不连续

7 v = range(0, 100, 5)8

9 for item inv:10 print(item)

View Code

28.zip()

421b95ee84055d49481e08bce750250d04b.jpg

067150a32c2159efe41d93ac40abdda715c.jpg

1 #print(list(zip(('a','n','c'),(1,2,3))))

2 #print(list(zip(('a','n','c'),(1,2,3,4))))

3 #print(list(zip(('a','n','c','d'),(1,2,3))))

4 #5 #p={'name':'alex','age':18,'gender':'none'}

6 #print(list(zip(p.keys(),p.values())))

7 #print(list(p.keys()))

8 #print(list(p.values()))

9 #10 print(list(zip(['a','b','c'],'12345')))

View Code

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值