2: 2017-01-02 (月) 07:20:11 njf  |
現: 2017-05-25 (木) 01:59:32 njf  |
| | def testFunc(): | | def testFunc(): |
| | print "test" | | print "test" |
| | + | |
| | testFunc() | | testFunc() |
| | | | |
| | def testFunc(a,b,c): | | def testFunc(a,b,c): |
| | print "a:%s,b:%s,c:%s" % (a,b,c) | | print "a:%s,b:%s,c:%s" % (a,b,c) |
| | + | |
| | testFunc("a","b","c") | | testFunc("a","b","c") |
| | | | |
| | def testFunc(a, b = "b", c = "c"): | | def testFunc(a, b = "b", c = "c"): |
| | print "a:%s,b:%s,c:%s" % (a,b,c) | | print "a:%s,b:%s,c:%s" % (a,b,c) |
| | + | |
| | testFunc("a","b") | | testFunc("a","b") |
| | | | |
| | for i in i_list: | | for i in i_list: |
| | print i | | print i |
| | + | |
| | testFunc(1,2) | | testFunc(1,2) |
| | | | |
| | for k,v in i_dic.iteritems(): | | for k,v in i_dic.iteritems(): |
| | print k,v | | print k,v |
| | + | |
| | testFunc(A='a',B='b') | | testFunc(A='a',B='b') |
| | | | |
| | def testFunc(a, b, c): | | def testFunc(a, b, c): |
| | print "a:%s,b:%s,c:%s" % (a,b,c) | | print "a:%s,b:%s,c:%s" % (a,b,c) |
| | + | |
| | f = testFunc | | f = testFunc |
| | + | |
| | f("a","b","c") | | f("a","b","c") |
| | | | |
| | a:a,b:b,c:c | | a:a,b:b,c:c |
| | | | |
| - | ただし、定義と共に変数や関数の引数には入れられないため、その場合はラムダ式を使います。ラムダ式については「[[Python/ラムダ式]]」を参照のこと。 | + | ただし、定義と同時に変数や関数の引数には入れられないため、その場合はラムダ式を使います。ラムダ式については「[[Python/ラムダ式]]」を参照のこと。 |
| | | | |
| | **再帰関数 [#ed12d72f] | | **再帰関数 [#ed12d72f] |
| | print n | | print n |
| | printN(n-1) | | printN(n-1) |
| | + | |
| | printN(3) | | printN(3) |
| | | | |
| | """print a,b,c""" | | """print a,b,c""" |
| | print "a:%s,b:%s,c:%s" % (a,b,c) | | print "a:%s,b:%s,c:%s" % (a,b,c) |
| - | | + | |
| | + | |
| | print testFunc.__doc__ | | print testFunc.__doc__ |
| | | | |