LinkedIn Python Skill Assessment Quiz Answers

What is the purpose of the “self” keyword when defining or calling instance methods?

Latest Update on 25th January, 2022 by Certification Course Answers

What is the purpose of the "self" keyword when defining or calling instance methods?

  1.  self means that no other arguments are required to be passed into the method.
  2.  There is no real purpose for the self method; it’s just historic computer science jargon that Python keeps to stay consistent with other programming languages.
  3.  self refers to the instance whose method was called.
  4.  self refers to the class that was inherited from to create the object using self.

Correct Answer:

  •  self refers to the instance whose method was called.

Simple example

class my_secrets:
    def __init__(self, password):
        self.password = password
        pass
instance = my_secrets('1234')
instance.password
>>>'1234'

Latest Updates

No posts found in this category.