불리언 - 논리 데이터 타입

Python의 데이터 타입

Jason Myers

Instructor

데이터 타입으로서의 불리언

  • True
  • False

대소문자에 유의하세요. Python과 다른 언어를 오갈 때 혼동될 수 있습니다.

out_of_cookies = True
if out_of_cookies:
    print("Run to the store NOW!")
Run to the store NOW!
Python의 데이터 타입

Truthy와 Falsey

  • Truthy 값은 true로 평가됩니다
  • Falsey 값은 false로 평가됩니다
apples=2
if apples:
     print("We have apples.")
"We have apples."
apples=0
if apple:
     print('We have apples.')
Python의 데이터 타입

Truthy와 Falsey

Truthy

  • 1
  • "Cookies"
  • ["Cake", "Pie"]
  • {"key": "value"}

Falsey

  • 0
  • ""
  • []
  • {}
  • None
Python의 데이터 타입

연산자 - 불리언 평가 컨텍스트

cookie_qty == 3
  • == 같음
  • != 같지 않음
  • < 보다 작음
  • <= 작거나 같음
  • > 보다 큼
  • >= 크거나 같음
Python의 데이터 타입

부동소수점은 대략적으로만 맞습니다

x = 0.1 + 1.1
x == 1.2
False
print(x)
1.2000000000000002

부동소수점의 동등 비교에 주의하세요!

Python의 데이터 타입

연습해 봅시다!

Python의 데이터 타입

Preparing Video For Download...