Skip to main content

maybe_as_string

Converts the input to a string if it is not already one, or returns the original value if it is already a string or cannot be converted.

def maybe_as_string(
value: any
) - > string | null

Converts a value to a string if it is not None, otherwise returns None. Use this to safely normalize optional data types for string-based processing or storage.

Parameters

NameTypeDescription
valueanyThe input value to be converted into a string representation.

Returns

TypeDescription
`stringnull`