Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

NISSO

[Python] 리스트로 True / False 출력 본문

Python

[Python] 리스트로 True / False 출력

oniss 2021. 6. 24. 22:16

리스트 자체로 True / False 결과를 출력할 수 있다.

 

def list_boolen(lst):
    if lst:
        print(True)
    else:
        print(False)
        
list_boolen([1,2])
list_boolen([])

 

답은 True, False

 

while 반복문에선 아래와 같이 활용할 수 있다.

 

i = 1
a = [1,2,3,4]
while a:
    print(i)
    i += 1
    a.pop(0)

 

이렇게 하면 1,2,3,4까지 나오고 멈춘다. 

a.pop(0)을 안 해주면 무한히 실행된다.

 

 

+ 문자열도 가능하다.

''는 False. ' '는 True

 

'Python' 카테고리의 다른 글

[Python] os 모듈의 유용한 함수 정리  (0) 2021.12.15
[Python] 코드 실행 시간 측정  (0) 2021.11.26
[Python] sort()와 sorted() 차이  (0) 2021.06.26
Comments