Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jennyonjourney/8eada43c28683607b6e09a1a7ea24f8d to your computer and use it in GitHub Desktop.
Save jennyonjourney/8eada43c28683607b6e09a1a7ea24f8d to your computer and use it in GitHub Desktop.
Python *
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