Python's self vs instance
<p>What is the difference between the self and instance keywords in Python 3?</p>

<p>I see code like,</p>

<pre><code>def update(self, instance, validated_data):
    """
    Update and return an existing `Snippet` instance, given the validated data.
    """
    instance.title = validated_data.get('title', instance.title)
    instance.code = validated_data.get('code', instance.code)
    instance.linenos = validated_data.get('linenos', instance.linenos)
    instance.language = validated_data.get('language', instance.language)
    instance.style = validated_data.get('style', instance.style)
    instance.save()
    return instance
</code></pre>

<p>Neither <code>self</code> nor <code>instance</code> are keywords in Python. The identifier <code>self</code> is used by convention as the first parameter of instance methods in a class. The object instance on which a method is called is automatically passed in as the first parameter.</p>

<p>In the above snippet, <code>update</code> is most probably a method of some class and <code>self</code> seems to be the conventional first parameter as described above. The second parameter <code>instance</code> is just another parameter and the name <code>instance</code> does not have any significance in Python.</p>

python django