Which decorator in Python is commonly used to define a method as a class property getter?
- @get
- @getter
- @method
- @property
To define a method as a class property getter in Python, the @property decorator is commonly used. This decorator allows you to access a method like an attribute, making it a clean way to implement read-only properties in classes.
Loading...
Related Quiz
- After installing a package using pip, a colleague isn't able to import it in their script. What could be a probable reason?
- You are experiencing performance bottlenecks in a Python program due to slow file I/O operations. How would you optimize the file reading and writing processes to improve performance?
- You are implementing a caching mechanism. You need a data structure that removes the least recently added item when the size limit is reached. Which built-in Python data structure would you use?
- If you're working with both CSV and JSON data formats in a project, which Python standard library module would be redundant?
- In terms of encapsulation, why might a developer use property decorators instead of directly accessing an attribute?