十分钟学会Python, 简单入门教程(21)

http://www.smzswang.com时间:2016-10-23 14:21来源:未知

  >>> print [x * y for x in lst1 for y in lst2]

  [3, 4, 5, 6, 8, 10, 9, 12, 15]

  >>> print [x for x in lst1 if 4 > x > 1]

  [2, 3]

  # Check if an item has a specific property.

  # "any" returns true if any item in the list is true.

  >>> any([i % 3 for i in [3, 3, 4, 4, 3]])

  True

  # This is because 4 % 3 = 1, and 1 is true, so any()

  # returns True.

  # Check how many items have this property.

  >>> sum(1 for i in [3, 3, 4, 4, 3] if i == 4)

  2

  >>> del lst1[0]

  >>> print lst1

  [2, 3]

  >>> del lst1

【免责声明】本文仅代表作者个人观点,与中国数码招商网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。您若对该稿件内容有任何疑问或质疑,请联系本网将迅速给您回应并做处理。

相关新闻