[Python] all(), any() 함수

Jay·2020년 5월 13일
0

all(), any() 함수는 파이썬 빌트인 함수이며 조건 성립 유무에 따라 True / False를 리턴해준다. 인자는 하나만 올 수 있고, 리스트여야한다.

  1. All
    조건이 전부 True면 True를 리턴하고, 하나라도 틀릴 경우 False를 리턴한다.
print (all([True, True, True, True])) 
> True
print (all([False, True, True, False])) 
> False
print (all([False, False, False])) 
> False
print(all([8,3,5,0]))
> False
print(all([8,3,5,None]))
> False
  1. Any
    조건중 하나라도 맞으면 True를 리턴한다.
print(any([False, False, False, False])) 
> False
print(any([False, True, False, False])) 
> True
print(any([True, False, False, False])) 
> True
print(any(['']))
> False
print(any[])
> False
print(any([8,3,5,None]))
> True

(파이썬에서는 빈 값, 0, None은 False로 인식한다.)

profile
You're not a computer, you're a tiny stone in a beautiful mosaic

0개의 댓글

관련 채용 정보