Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jennyonjourney/556284b808df174d03cf8fdaeb141357 to your computer and use it in GitHub Desktop.
Save jennyonjourney/556284b808df174d03cf8fdaeb141357 to your computer and use it in GitHub Desktop.
Python - 3/25 def 복습
def order(ih,name='아시아노'):
dd = {'아메리카노': 2000,
'아프리카노': 3000,
'아시아노': 3500}
print(name, ih, dd[name])
order('아이스','아메리카노')
order('핫','아프리카노')
order('아이스')
print('----실습----')
def school(name, aa='교수',*jum):
res=name+","+aa
if aa=='학생':
hap=0
for i in jum:
res+=","+str(i)
hap+=i
avg=hap/len(jum)
res+=","+str(hap)+","+str(avg)
print(res)
school('이교수')
school('장동건','교수')
school('한가인','학생')
----------------------------------
def fn1(arr):
hap=0
for i in arr:
hap+=1
print("fn1()",arr,hap)
fn1([11,22,33,44])
# 이렇게 튜플이 아니면 넣을수 없다 -> fn1(11,22,33,44)
# 열거형은 맨 뒤에서 온다.
def fn2(*arr): #앞에 별표를 넣으면 에러가 나지 않는다.
hap=0
for i in arr:
hap+=1
print("fn1()", arr, hap)
fn1([11,22,33,44])
fn2("무슨소리인지","모르겠어요","선생님")
# *별표는 아트랙스란 애래. 나머지 모든 것이라는 의미래.
def fn3(a, b, *c):
print("fn3()", a,b,c)
fn3(1,3,5,7,9)
fn3(1,3,5,7)
fn3(1,3,5)
# fn3(1,3)
# 이렇게 하면 에러가 된다 def fn4(a,*b,c):
# 아래처럼 하면 에러가 되지 않는다. b=1234가 결국 원소하나만 나오면 나머지는 걍 b=1234로 알게 라는 뜻.
def fn5(a,b=1234):
print('fn5()',a,b)
fn5(1)
# 초기값을 주는 것은 뒤에서 부터 준다.
def fn6(c=5678, d=1234):
print('fn6()',c,d)
fn6(12)
def fn7(a, b, c=1234, *d):
print("fn7() 시작>>")
print("a:",a)
print("b:",b)
print("c:",c)
print("d:",d)
print("fn7() 끝")
fn7(12,34,56,78,90)
print('----------')
fn7(12,34,56,78)
print('----------')
fn7(12,34,56)
print('----------')
fn7(12,34)
#fn7(12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment