개발자를 위한 Python 입문
Jasmin Ludolf
Senior Data Science Content Developer
# Boolean variable
the_truth = True
print(the_truth)
True
비교 연산자
두 가지가 같은지 확인
==# Compare if 2 is equal to 3
2 == 3
False
# Check that 2 is not equal to 3
2 != 3
True
# Is 5 less than 7?
5 < 7
True
# Is 5 less than or equal to 7?
5 <= 7
True
# Is 5 greater than 7?
5 > 7
False
# Is 5 greater or equal to 7?
5 >= 7
False
# Is James greater than Brian
"James" > "Brian"
True
if 조건이 충족되면 작업을 수행하고, 그렇지 않으면 건너뜁니다# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity
if 조건이 충족되면 작업을 수행하고, 그렇지 않으면 건너뜁니다# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:
if 조건이 충족되면 작업을 수행하고, 그렇지 않으면 건너뜁니다# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")
# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!") # This line is not indented
print("You have enough pasta!")
^
IndentationError: expected an indented block
# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")elif pasta_quantity >= 300: print("Nearly enough pasta. Try a smaller portion.")
elif 키워드를 원하는 만큼 사용할 수 있습니다!# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")elif pasta_quantity >= 300: print("Nearly enough pasta. Try a smaller portion.")# Otherwise... else: print("Not enough pasta.")
Not enough pasta.
| 연산자 | 기능 |
|---|---|
== |
같음 |
!= |
같지 않음 |
> |
보다 많음 |
>= |
크거나 같음 |
< |
미만 |
<= |
작거나 같음 |
| 키워드 | 기능 | 사용 |
|---|---|---|
if |
조건이 충족되는 경우 | 워크플로에서 먼저 |
elif |
그렇지 않으면 조건이 충족되는지 확인 | if 이후 |
else |
그렇지 않으면 이 작업 수행 | elif 이후 |
개발자를 위한 Python 입문