文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Python Object-oriented Shortcuts(Chapter 7 of Python 3 Object Oriented Programmi

Python Object-oriented Shortcuts(Chapter 7 of Python 3 Object Oriented Programmi

时间:2010-09-03  来源:Ray Z

  Len   The simplest example is the len() function. This function counts the number of items in some kind of container object such as a dictionary or list.

  Reversed 

    The reversed() function takes any sequence as input, and returns a copy of that sequence in reverse order.

  Enumerate 

  Sometimes when we're looping over an iterable object in a for loop, we want access to the index (the current position in the list) of the current item being processed. The for loop doesn't provide us with indexes, but the enumerate function gives us something better: it creates a list of tuples, where the first object in each tuple is the index and the second is the original item. 

  Zip

  The zip function is one of the least object-oriented functions in Python's collection. It takes two or more sequences and creates a new sequence of tuples. Each tuple contains one element from each list. 

 

  Three more functions that operate on sequences are min, max, and sum. These each take a sequence as input, and return the minimum or maximum value, or the sum of all values in the sequence. 

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载