2: 2017-01-02 (月) 07:20:11 njf[4] [5] [6] | 現: 2017-05-25 (木) 01:59:32 njf[4] [7] [8] | ||
---|---|---|---|
Line 5: | Line 5: | ||
def testFunc(): | def testFunc(): | ||
print "test" | print "test" | ||
+ | |||
testFunc() | testFunc() | ||
Line 16: | Line 16: | ||
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") | ||
Line 45: | Line 45: | ||
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") | ||
Line 66: | Line 66: | ||
for i in i_list: | for i in i_list: | ||
print i | print i | ||
+ | |||
testFunc(1,2) | testFunc(1,2) | ||
Line 86: | Line 86: | ||
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') | ||
Line 107: | Line 107: | ||
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") | ||
Line 115: | Line 115: | ||
a:a,b:b,c:c | a:a,b:b,c:c | ||
- | ただし、定義と共に変数や関数の引数には入れられないため、その場合はラムダ式を使います。ラムダ式については「[[Python/ラムダ式]]」を参照のこと。 | + | ただし、定義と同時に変数や関数の引数には入れられないため、その場合はラムダ式を使います。ラムダ式については「[[Python/ラムダ式]]」を参照のこと。 |
**再帰関数 [#ed12d72f] | **再帰関数 [#ed12d72f] | ||
Line 123: | Line 123: | ||
print n | print n | ||
printN(n-1) | printN(n-1) | ||
+ | |||
printN(3) | printN(3) | ||
Line 137: | Line 137: | ||
"""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__ | ||
(This host) = https://njf.jp