一些函数的学习

在学习python的过程中,有些函数会经常用到,因此经常总结一些常用函数是非常有必要的。

1、bytearray.isdigit()

2、enumerate(iterable, start=0) 

1bytearray.isdigit() #判断字符是否为数字字符串

Return true if all bytes in the sequence are ASCII decimal digits and the sequence is not empty, false otherwise.
ASCII decimal digits are those byte values in the sequence b'0123456789'.
1 >>> '123'.isdigit()
2 True
3 >>> '123w'.isdigit()
4 False

2、enumerate(iterable, start=0) #枚举函数,返回包含计数的一个元组

Return an enumerate object. iterable must be a sequence, an iterator,or some other object which supports iteratior.

The __next__() method of the iterator returned by enumerate()returns a tuple containing a count (from start which defaults to 0)and the values obtained from iterating over iterable.
#返回一个枚举类型,迭代式必须是一个序列,一个迭代式或者支持迭代的其它对象。
#返回一个包含计数的元组(默认从0开始计数)并且从不断迭代所获得的值
 1 >>> a=['wuchao','jinxing','xiaohu','sanpang','eer','zhou','zhou']
 2 >>> b=enumerate(a,1)    #生成一个enumerate类的对象
 3 >>> for x in b:         #遍历整个对象
 4      print (x)          #打印
 5 
 6 (1, 'wuchao')        #生成元组
 7 (2, 'jinxing')
 8 (3, 'xiaohu')
 9 (4, 'sanpang')
10 (5, 'eer')
11 (6, 'zhou')
12 (7, 'zhou')
 1 eg2  #此种方法把b列表中的每个元素中的值分别取出
 2    >>> for x,i in b:         #类似于此  >>> a,b=2,3
 3            print(x,i)        #         >>> print (a,b)
 4                              #            2 3
 5 
 6 1 wuchao
 7 2 jinxing
 8 3 xiaohu
 9 4 sanpang
10 5 eer
11 6 zhou
12 7 zhou



 

猜你喜欢

转载自www.cnblogs.com/alen1/p/9548966.html
今日推荐