LoginSignup
0
0

More than 3 years have passed since last update.

rubyとpythonのif文の書き方の違い

Posted at

Progateでpythonの基本的な文法を勉強中なので、rubyとの違いをまとめておく。

rubyのif文

・if〜endで囲む

x = 100

if x == 100
 print "xは100です"
else
 print "xは100じゃないです"
end

pythonのif文

・条件式の最後に「:(コロン)」をつける
・実行する処理の記述はインデントする

x = 100
if x == 100:
    print('xは100です')
else:
    print('xは100じゃないです')

pythonはインデントが動作に直接影響するから、自然と可読性が高いコードになりそうで良き

0
0
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
0