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