Toggle

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Oct 10 03:15:47 EDT 2014


Rustom Mody wrote:

> In fact this:
>> >>> Color.blue.toggle()
>> <Color.red: 0>
>> >>> Color.blue.toggle().toggle()
>> <Color.blue: 1>
> 
> is a nice example of a pattern that is rarely seen:
> OO syntax, functional (ie non-state-changing) semantics.

You don't write much Python code, do you? *wink*

It is not "rarely seen" in Python:

some_string.strip().replace("x", "y").upper().split()

sort of thing is extremely common in Python.



-- 
Steven




More information about the Python-list mailing list