Q. Which of the following defines a property in Python?

  • (A) def get_name(self): return self.name
  • (B) @property def name(self): return self._name
  • (C) name = get_name()
  • (D) self.name = 'abc'
πŸ’¬ Discuss
βœ… Correct Answer: (B) @property def name(self): return self._name
Explanation: The @property decorator is used to define getter methods as attributes.
Explanation by: Mr. Dubey
The @property decorator is used to define getter methods as attributes.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
67
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
84%
Success Rate