Python > メソッド(関数)の定義
更新日
2015-04-23
広告
Pythonでメソッドを定義する方法を紹介します。
以下は、usageというメソッドを定義して、呼び出す例です。
def usage(): print 'USAGE: hogehoge' usage() # invoke以下は、2つの引数を取るメソッドを定義する例です。
def test(a, b): print a print b test('hoge', 5) # invoke test(50, 'aa') # invoke返り値を返すには return を使います。
def add(a, b): return a + b c = add(1, 2) # c == 3複数の返り値を返すことも簡単です。以下はその例です。
def hoge(): return [1, "a"] number, text = hoge() print number print text
広告
お問い合わせは sweng.tips@gmail.com まで。