diff --git a/LectureNote-7(2).py b/LectureNote-7(2).py new file mode 100644 index 0000000000000000000000000000000000000000..124c52fcb1cf8389bf8e93cf3426782d2019f1e6 --- /dev/null +++ b/LectureNote-7(2).py @@ -0,0 +1,70 @@ +Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28) +[Clang 6.0 (clang-600.0.57)] on darwin +Type "help", "copyright", "credits" or "license()" for more information. +>>> +>>> def hello_korean(): + print('hello') + + +>>> def hello_english(): + print('hello') + + +>>> def hello_korean(): + print('안녕하세요') + + +>>> def get_greeting(where): + if where == 'k': + return hello_korean + else: + return hello_english + + +>>> hello=get_greeting(k) +Traceback (most recent call last): + File "<pyshell#16>", line 1, in <module> + hello=get_greeting(k) +NameError: name 'k' is not defined +>>> hello=get_greeting('k') +>>> hello +<function hello_korean at 0x112374400> +>>> hello() +안녕하세요 +>>> hello2=get_greeting('e') +>>> hello2() +hello +>>> #중첩 함수 +>>> import math +>>> def stddev(*args): + def mean(): + return sum(args)/len(args) + def variance(m): + total = 0 + for arg in args: + total +=(arg - m) ** 2 + return total/(len(args)-1) + v=variance(mean()) + return math.sqrt(v) + +>>> stddev(2.3,1.7,1.4,0.7,1.9) +0.6 +>>> stddev(1,2,3) +1.0 +>>> mean() +Traceback (most recent call last): + File "<pyshell#37>", line 1, in <module> + mean() +NameError: name 'mean' is not defined +>>> #pass키워드는 함수나 클래스의 구현을 미룰때 사용 +>>> def empty_function() +SyntaxError: invalid syntax +>>> def empry_class: + +SyntaxError: invalid syntax +>>> def empty_function(): + pass +class empty_class: + +SyntaxError: invalid syntax +>>>