Talk:Python is Magic/Constants
Jump to navigation
Jump to search
Apparently there are some versions of Python where __doc__
is not None. I'll rework this soon. --PkmnQ (talk) 12:02, 30 September 2024 (UTC)
j
and y
You might be curious why the constants for j
and y
work, in fact, they come from the docs for str and __builtins__.
str.__doc__:
str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.
__builtins__.__doc__:
Built-in functions, exceptions, and other objects.
Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices.
Idk if Python will change its docs for these objects, but I've tested both of them on Python 3.11 and 3.7 for windows and TIO, and they return the correct results. --None1 (Nope.) 11:31, 28 September 2024 (UTC)
- In case
str
's docstring ever changes in such a way that the above no longer works, a replacementj
is__doc__.__format__.__doc__.__getitem__(__doc__.__format__.__name__.__len__())
. --PkmnQ (talk) 12:10, 28 September 2024 (UTC)