0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Python] if 文

Last updated at Posted at 2020-05-20

if文

注意点
・条件式の後に :
・else if は elif
・条件式左右等しい時は ==

if money > total_price:
    print("りんごを" + str(count) + "個買いました")
    print("残金は" + str(money - total_price) + "円です")
elif money == total_price:
    print("りんごを" + str(count) + "個買いました")
    print("財布は空になりました")
else:
    print("お金が足りません")
    print("りんごを買えませんでした")

###条件式組み合わせ
and
どちらの条件も満たす

if time > 10 and time < 15:

or
どちらか一方の条件を満たす

if time == 10 or time == 15:

not
条件の否定

if not time == 20:

比較演算子

jsと違い左右が等しい時の=の数などが変わる。
image.png

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?