LoginSignup
0
2

More than 3 years have passed since last update.

returnの使い方

Posted at

returnとは?

・返り値がない場合とある場合の2種類がある

return(返り値がない場合)

def a(x,y):
    if x==y:
        print("same")
        return
        print(x,y)
    else:
        print("different")
a(1,1)
a(1,0)
実行結果
same
different 

・returnの後のprint(x,y)は実行されない

return(返り値がある場合)

def a(x,y):
    if x==y:
        return ("{}と{}は等しい").format(x,y)
    else:
        return ("{}と{}は等しくない").format(x,y)
a(1,1)
a(1,0)
実行結果
'1と1は等しい'
'1と2は等しくない'
0
2
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
2