程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python check if all elements of list list are true

編輯:Python

Function introduction

all()

Used to determine whether all elements in the given iterable parameter iterable are TRUE, if so, return True, otherwise return False.

Elements are True except 0, empty, None, False.

any()

The opposite of all()

Syntax

all(iterable)

Instance

>>> all(['a', 'b', 'c', 'd']) # list list, none of the elements are empty or 0True>>> all(['a', 'b', '', 'd']) # list list, there is an empty elementfalse>>> all([0, 1, 2, 3]) # list list, there is an element that is 0false>>> all(('a', 'b', 'c', 'd')) # tuple, none of the elements are empty or 0True>>> all(('a', 'b', '', 'd')) # tuple, there is an empty elementfalse>>> all((0, 1, 2, 3)) # tuple tuple, there is an element that is 0false>>> all([]) # empty listTrue>>> all(()) # empty tupleTrue

Self-encoding judgment

def testfunc(page, locator, rearg, *args):print(type(page), page)print('locator: ', locator)print('url: ',rearg)print('args: ',args)def is_pass(df_result):for i in range(len(df_result)):if df_result[i] == 'pass' or df_result[i] == '':df_result[i] = 1else:df_result[i] = 0if 0 in df_result:return Falseelse:return True

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved