Skip to content
Snippets Groups Projects
Commit 2b2a8fb5 authored by KimMinSeob's avatar KimMinSeob
Browse files

Upload New File

parent f245abcb
No related branches found
No related tags found
No related merge requests found
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
>>>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment