all(iterable) : 리스트나 튜플 요소가 모두 참인 경우 True 반환. 하나라도 거짓이 있으면 False
any(iterable) : 리스트나 튜플 의 요소가 모두 거짓인 경우 False 반환. 하나라도 참이 있으면 True
파이썬에서는 아래 요소에 대해서는 거짓(False)으로 판단
- 숫자 0 (zero)
- 빈 문자열 '', "", ''''''
- 빈 리스트 [ ]
- 빈 튜플 ( )
- 빈 사전 { }
- None
all - 모든요소가 참 일 때,
lst = ['1','2', 'a', 1, 0.1]
all(lst)
-----------------------------
True
all - 요소 중 하나가 거짓 일 때
lst = ['1','2', 'a', 1, 0.1, 0 ] # 숫자 0
all(lst)
---------------------------------
False
lst = ['1','2', 'a', 1, 0.1, {} ] # 빈 사전
all(lst)
---------------------------------
False
lst = ['1','2', 'a', 1, 0.1, [] ] # 빈 리스트
all(lst)
---------------------------------
False
lst = ['1','2', 'a', 1, 0.1, '''''' ] # 빈 문자열
all(lst)
---------------------------------
False
any - 모든 요소가 거짓 일 때,
lst = [ [], (), {}, 0, None ]
any(lst)
-----------------------------
False
all - 요소 중 하나가 참 일 때
lst = [ [], (), {}, 0, None, 1 ]
any(lst)
---------------------------------
True
'Python > Python Programming' 카테고리의 다른 글
[Python] Add date string and time string of pandas Dataframe (pandas의 date와 time 문자열을 합친 날짜형식 만들기) (0) | 2019.10.14 |
---|---|
[Python] Convert time string type to datetime date type. (날짜문자열을 타임 타입으로 변환) (0) | 2019.10.14 |
[Python] Convert time string type to datetime time type. (시간문자열을 타임 타입으로 변환) (0) | 2019.10.14 |
[Python] Website image download (0) | 2019.10.11 |
[Python] isalpha 문자열에 문자만 있는지 확인하는 메소드 (0) | 2019.10.11 |
[Python] multiplication table (파이썬 구구단) (0) | 2019.10.10 |
[Python] multiplication table using itertools module. (itertools을 이용한 구구단) (0) | 2019.10.10 |
[Python] comparing a file and b file (파일 비교 하기) (0) | 2019.10.10 |