QamoosTech
Programming FundamentalsObject-oriented programmingIntermediatePython

Property

PronunciationPROP-er-tee

Definition

A property looks like a plain attribute but runs code when you read or write it, which lets a class validate values or compute them on demand.

Where you hear it

In Python and C# classes, code reviews about validation, and discussions of getters and setters.

Examples

  • balance is a read-only property, so callers cannot assign to it.
  • The setter rejects negative ages.
  • The total property is computed from the line items every time it is read.

Common mistake

Hiding slow work behind a property. People expect reading an attribute to be quick and free of side effects.

Don't confuse with

A method, which you call with parentheses. A property is used without them.

Say it at work

  • In a meeting or chatTurn that getter into a property so callers keep the simple syntax.
  • In an email or ticketValidate it in the setter, not at every call site.