Just like UserDict
and UserList
, UserString
is a string wrapper that allows easier subclassing of strings due to providing the underlying string as an attribute. The preferred way to do this is to subclass string
directly; this class is provided mainly due to backwards-compatibility or simple cases where subclassing string
is overkill for functionality.
While all string methods are available, such as UserDict
and UserList
, UserString
adds the data
attribute for easy access to the underlying string object. The contents of UserString
are initially set to a copy of some type of sequence; the sequence can be bytes, a string, another UserString
or subclass, or any other sequence object that can be converted to a string.