1. int 类型转换
a = "123"b = int(a)b = b+10print(type(a),a)print(type(b),b)
2. int(num,base=2), base不写的时候默认为10
a = "0011"b = int(a,base=2)print(b)
答案为 3.
3. -.bit_length() 当前数字为2进制时,至少要用多少位来表示
a = 8b = a.bit_length()print(b)
answer:4
4. str 居住 center()
a = "kkkk"b = a.center(20,"&")print(b)#"&"中只能填一个&&&&&&&&kkkk&&&&&&&&
5. str 之count()计数
count(self, sub, start=None, end=None)
a = "kkkkrrrrrrrrrxxxxxxxxx"b = a.count('r',5,14)print(b)8
6. find(self, sub, start=0, end=_sys.maxsize) 比index()好用
a = "djalskfjs;kd k"b = a.find("ja",0,20)print(b)1
7. format(self, *args, **kwargs ) 两种方式效果一样
a = 'jkldak{ff},ioeu{gg}'b = a.format(ff='JOAN',gg='HUMAN')print(b)a = 'jkldak{0},ioeu{1}'b = a.format('JOAN','HUMAN')print(b)jkldakJOAN,ioeuHUMAN
8. format_map(self, mapping)
format_map(self, mapping): # real signature unknown; restored from __doc__
9. def isalnum(self, *args, **kwargs): # real signature unknown
Return True if the string is an alpha-numeric string, False otherwise.