美文网首页
python常用对象

python常用对象

作者: 西伯利亚狼_ | 来源:发表于2018-12-20 18:19 被阅读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

相关文章

网友评论

      本文标题:python常用对象

      本文链接:https://www.haomeiwen.com/subject/uxlukqtx.html