学习第3天

dir (str)   显示所有类成员 

type()    获取类属性 

 

STR 内 方法 :

1 __add__

2__contains__      字符串中是否包含某个子项

3 __eq__   等于 

4__format__   格式化   

   

5__getattritute__      反射

6__getitem__

7__getnewargs__

8__gt__

9

10

11

12

13

 

1capitalize(self)     首字母大写

2casefold(self)  首字母变小写

3center(self,width,fillchar=None)        居中 

      name=liujun

      result=name.center(20,*)

      print(result)

4count(self,sub,start=None,end=None)    查找字符串中子项个数

5encode(self,encoding='utf-8',errors='strict' )

     name=李姐

     name.encode('gbk')    # 结果转换成gbk编码 ,   unicode   gbk   utf-8  

6endswith(self,suffix,start=None,end=None)

7expandtabs(self,tabsize=8)   tab转为空格 ,默认8个空格

8find(self,sub,start=None,end=None)    查找字符串中子项 ,返回所在起始位置,不存在返回-1

 功能 类似 index,没找到抛异常

9 format(*args,**kwargs)

 

     name=" liujun  {0}   is  {1}"

     result=name.format('boy','good')

     print(result)          #liujun  boy  is  good

10 format map()

 

11 index

12 isalnum(self)

13 isalpha

14 isdecimal

15 isdigit

16 isidentifier

17 islower

18 isnumeric

19 isprintable

20 isspace

21 istitle

22 isupper

23 join(self,iterable)

     li=['s','a','e','l','u','n','j','u','n']

     result=.join(li)

     result='_'.join(li)

24 rjust    置右

     ljust     置左

     center   置中

25  lower

26 lsrtip      清除左边空格

     rstrip

27  maketrans ()       建立两个字符串的对应关系

 

28 partition(self,sep)          利用sep进行分割字符串

29 replace(self,old,new,count=None)         用new 替换old   

30  rfind (self,sub,start=   ,  end=    )

      lfind

31  rindex

      lindex

32 rpartition(self,sep)

     lpartition(self,sep)

33

posted on 2017-08-26 13:51  风云小析  阅读(105)  评论(0编辑  收藏  举报