開発者のためのPython入門
Jasmin Ludolf
Senior Data Science Content Developer
# Boolean variable
the_truth = True
print(the_truth)
True
比較演算子
2つのものが等しいか確認する
==# 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入門