본문 바로가기
Python/DataType&Structure

bool type

by youngflowey 2019. 11. 26.

Bool Type ( bool ) : 논리타입 
                          True, False 가지는 타입 
                   = and 연산자 : 논리연산자, or : 논리연산자, not : 논리연산자

result = True and False
print(result)
result = not True
print(result)
##          = & : 비교연산자, bitwise연산
result = True & False

 

 

pyton에서 숫자 0은 False로 간주, 0이 아닌 모든 숫자 True로 간주

print(bool(0))
## 숫자 0을 True나 False로 바꿔라
print(bool(1))
## python 에서 False는 숫자 0으로 변환
print(int(False))
## Treu를 숫자로 바꾸면
print(int(True))

  • 10진수 5를 2진수 => 0101 
    10진수 1을 2진수 => 0001
  • True & False => 1 & 0 => 0001 & 0000 => 0000 => 0 => False

 

python은 다음이 경우를 False로 간주

  • 숫자0, 빈 문자열(''), 빈 리스트([]), 빈 튜플( () ), 비어있는 idc( {} ), None
print(bool("소리없는 아우성!!"))
print(bool([1]))
print(bool({tuple}))
print(bool(None))

 

'Python > DataType&Structure' 카테고리의 다른 글

제어문  (0) 2019.11.26
set type  (0) 2019.11.26
Mapping Type - dic(dictionary)  (0) 2019.11.26
Sequence Type - range  (0) 2019.11.26
Sequence Type - tuple  (0) 2019.11.26

댓글