Language/Python
Python - any(), 반복 가능한 자료형 내 element 중 하나라도 True인지 확인하는 함수
TechNote.kr
2017. 12. 27. 21:17
728x90
any
>>> any(iterableValue)
전달받은 자료형의 element 중 하나라도 True일 경우 True를 돌려준다.
(만약 empty 값을 argument로 넘겨주었다면 False를 돌려준다.)
__builtin__ module에 포함된 function 이다.
내부 구현 (from python official docs)
def any(iterable): for element in iterable: if element: return True return False
예)
iterable 자료형내 element가 모두 False일 경우
>>> a = [False,False,False]
>>> any(a) False
iterable 자료형내 element 중 True가 있을 경우
>>> a = [True,False,True] >>> any(a) True
empty를 넘겨주었을 경우
>>> a = [] >>> any(a) False
참고>
>>> help(any)
Help on built-in function any in module __builtin__:
any(...)
any(iterable) -> bool
Return True if bool(x) is True for any x in the iterable.
If the iterable is empty, return False.
728x90