python tuple

610 단어 python
django 소스 코드 를 보고 있 는데 이렇게 되 돌아 오 는 방법 이 많 습 니 다.
def save:
     # some code
     return success,model

 
코드 를 호출 하 는 것 은 매우 간단 하 다.
created, message = Message.objects.save()

if  created:
    print message

 
앞에서 이 쓰 기 는 python 의 특수 한 유형 tuple 을 사 용 했 습 니 다.tuple 은 가 변 적 이지 않 은 list 입 니 다.python 은 tuple 을 이렇게 정의 할 수 있 습 니 다.
http_msg = 404,"NOT FOUND"

 
tuple 을 사용 하면 간단 합 니 다:
code,msg = http_msg

좋은 웹페이지 즐겨찾기