python常用对象

2018-12-20  本文已影响7人  西伯利亚狼_

1. sorted()

对可迭代对象进行排序
sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list

>>> a = [12, 98, 23, 34, 17]
>>> sorted(a)
[12, 17, 23, 34, 98]

2. max()

获取可迭代对象或者多个参数的最大值
max(iterable[, key=func]) -> value
max(a, b, c, ...[, key=func]) -> value

With a single iterable argument, return its largest item.
With two or more arguments, return the largest argument.

>>> a = [12, 98, 23, 34, 17]
>>> max(a)
98

3. min()

获取可迭代对象或者多个参数的最小值
min(iterable[, key=func]) -> value
min(a, b, c, ...[, key=func]) -> value

With a single iterable argument, return its smallest item.
With two or more arguments, return the smallest argument.

>>> a = [12, 98, 23, 34, 17]
>>> min(a)
12

4. len()

获取一个序列或者集合的长度
len(object) -> integer

Return the number of items of a sequence or collection.

>>> a = [12, 98, 23, 34, 17]
>>> len(a)
5

5. index()

获取列表中值所对应的索引值
L.index(value, [start, [stop]]) -> integer -- return first index of value.
Laises ValueError if the value is not present.

>>> a = [12, 98, 23, 34, 17]
>>> a.index(98)
1
上一篇 下一篇

猜你喜欢

热点阅读