LinkedIn Python Skill Assessment Quiz Answers

What does a class’s init() method do?

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

What does a class's init() method do?

  1.  The __init__ method makes classes aware of each other if more than one class is defined in a single code file.
  2.  The__init__ method is included to preserve backwards compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.
  3.  The __init__ method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.
  4.  The __init__ method initializes any imports you may have included at the top of your file.

Correct Answer:

  •  The __init__ method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.

Example:

class test:
    def __init__(self):
        print('I came here without your permission lol')
        pass
t1 = test()
>>> 'I came here without your permission lol'

Latest Updates

No posts found in this category.