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>The question is rather generic, but let me see if I can shed some light on it for you:</p>

<p><code>self</code> refers to the class(by convention, not a keyword) of which <code>update</code> is a part. The class has variables and methods and you can refer to these with the <code>self</code> keyword(not a reserved keyword) by calling <code>self.update(instance, validated_data)</code></p>

<p>In the case of the snippet above, <code>self</code> refers to the class. <code>instance</code> likely refers to some <code>model</code> instance "the big hint is the <code>instance.save()</code> and <code>validated_data</code> is a dictionary or class object with attributes you are <code>get</code>tting and assigning to <code>instance</code> attributes before saving them</p>

<p>Hope this helps</p>

python django