day04-作业

2018-12-28  本文已影响0人  馒头不要面

1.capitalize()

str1 = 'abc' 
print(str1.capitalize()) # Abc

2.center(width, fillchar)

str1 = 'abc'
print(str1.center(7, '0')) # 00abc00

3.count(str)

print('abc and abc'.count('a')) # 3

4.bytes.decode(encoding="utf-8", errors="strict")

str = b'hello world'
str.decode(encoding='utf-8') # 'hello world'

5.encode(encoding='UTF-8',errors='strict')

'hello world'.encode(encoding='utf-8') # b'hello world'

6.endswith(suffix)

'hello world'.endswith('d') # True

7.expandtabs(tabsize=8)

A = '       abc'
len(A) # 4
len(A.expandtabs()) # 11

8.find(str, beg=0 end=len(string))

A = 'hello world'
A.find('o',6,9) # 7

9.index(str, beg=0, end=len(string))

A = 'hello world'
A.index('o',6,9) # 7

10.isalnum()

A = 'hello world'
A.isalnum() # False

11.isalpha()

A = 'helloworld'
A.isalpha() # True

12.isdigit()

A = '123'
A.isdigit() # True

13.islower()

A = 'a123'
A.islower() # True

14.isnumeric()

A = '二十'
A.isnumeric() # True

15.isspace()

A = ' '
A.isspace() # True
A = ' abc'
A.isspace() # False 

16.istitle()

A = 'Abc Def Ghi'
A.istitle() # True

17.isupper()

A = 'Abc 123'
A.isupper() # False
A = 'ABC 123'
A.isupper() # True

18.join(seq)

A = '-'
A.join('1234') '1-2-3-4'

19.len(string)

A = 'ABC'
len(A) # 3

20.ljust(width[, fillchar])

A = 'ABC'
A.ljust(6,'0') # ruturn 'ABC000‘

21.lower()

A = 'ABC'
A.lower() # 'abc'

22.lstrip()

A = ' abc'
A.lstrip() # 'abc'
A = '?abc'
A.lstrip('?' # 'abc'

23.max(str)

A = 'cda'
max(A) # 'd'

24.min(str)

A = 'cda'
min(A) # 'a'

25.replace(old, new [, max])

A = 'abc cba abc cad'
A.replace('abc', '111', 1) # '111 cba abc cad'

26.rfind(str, beg=0,end=len(string))

A = 'abc cba abc cad'
A.rfind('abc') # 8

27.rindex( str, beg=0, end=len(string))

A = 'abc cba abc cad'
A.rindex('abc') # 8

28.rjust(width,[, fillchar]

A = 'abc'
A.rjust(6,'0') # '000abc'

29.rstrip()

A = 'abc    '
A.rstrip() # 'abc'

30.split(str="", num=string.count(str))

A = 'A B C D'
A.split() # ['A', 'B', 'C', 'D']
A = 'A,B,C,D'
A.split(',',2) # ['A', 'B', 'C,D']

31.splitlines([keepends]

A = 'A\rB\n'
print(A)
B

A.splitlines(True)
['A\r', 'B\n']
A.splitlines(False)
['A', 'B']

32.startswith(str, beg=0,end=len(string))

A = 'ABC'
A.startswith('A') # True

33.strip([chars])

A = '   ABC   '
A.strip() # 'ABC'
A = '?ABC?'
A.strip('?') # 'ABC'

34.swapcase()

A='ABCabc'
A.swapcase() # 'abcABC'

35.title()

A= 'abc cde'
A.title() # 'Abc Cde'

36.upper()

A = 'abc'
A.upper() # 'ABC'

37.zfill (width)

A = 'ABC'
A.zfill(6) # '000ABC'

38.isdecimal()

A = '\u4e00a'
A.isdecimal() # False
A = 'a'
A.isdecimal() # False
A = '10'
A.isdecimal() # True
上一篇 下一篇

猜你喜欢

热点阅读