반응형
  • 튜플은 () 로 정의된다
  • 튜플은 값을 바꿀수 없다.
t1 = ()
t2 = (1,)
t3 = (1,2,3)
t4 = 1,2,3
t5 = ('a', 'b', ('ab', 'cd'))
  • 1개의 요소만 가질때에는 콤마(,) 를 붙여야 한다.
  • 괄호가 생략 가능하다
  • 개수가 정해지지 않은 매개 변수로 사용된다. (* 가 매개변수 앞에 붙는다.) = 위치가변 매개변수
def print_fruits(*args):
  print(args)
  for arg in args:
    print(arg)

print_fruits('apple', 'banana', 'melon')

output
('apple', 'banana', 'melon')
apple
banana
melon

 

728x90
반응형

+ Recent posts