0

I'm currently reading some of the Django docs and I've come across this

    obj, created = Person.objects.get_or_create(first_name='John', last_name='Lennon',
              defaults={'birthday': date(1940, 10, 9)})

I'm still learning python in the process. I'm a bit confused with the "obj, created = " part of the code. I assume that both "obj" and "created" perform

    Person.objects.get_or_create(first_name='John', last_name='Lennon',
              defaults={'birthday': date(1940, 10, 9)})

1 Answer 1

2

Person.objects.get_or_create returns two values, which are assigned into obj and created respectively. obj is the actual object that was gotten or created, and created is a flag that tells you if it was created (or gotten).

Sign up to request clarification or add additional context in comments.

1 Comment

Returning multiple items from a function is one of the things that I liked in Perl when I did it, and I missed in C++ and Java. Faking with with structs or classes was really bogus.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.