Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, but YMMV (especially with automatic linters):
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
or on unhashable types (like list
).
The only other possibility I see is replacing the values for True, False, None
after the conversion to str
, unsing str.translate
, but this would be unable to differentiate None
and "None"
.
Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, but YMMV (especially with automatic linters):
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
or on unhashable types (like list
).
Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, but YMMV (especially with automatic linters):
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
or on unhashable types (like list
).
The only other possibility I see is replacing the values for True, False, None
after the conversion to str
, unsing str.translate
, but this would be unable to differentiate None
and "None"
.
Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, but YMMV (especially with automatic linters):
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
or on unhashable types (like list
).
Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, but YMMV (especially with automatic linters):
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
.
Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, but YMMV (especially with automatic linters):
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
or on unhashable types (like list
).
Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, IMObut YMMV (especially with automatic linters):
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
.
Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, IMO:
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
.
Even though return
cuts the chain short if one matches, I would prefer to use an elif
chain here, because it is more obvious, but YMMV (especially with automatic linters):
def stringify(value):
"""Returns the string representation of the value."""
if value is None:
return '-'
elif value is True:
return '✓'
elif value is False:
return '✗'
return str(value)
Apart from that there is no real alternative, because all other approaches will fail on the difference between 0
and False
, which you can only get with is
.