CKTIS / Python
repr()
Restituisce un testo di ispezione tramite `__repr__`.
Versione: Python 3.14; repository image, production runtime not attested
Sintassi
repr(object, /)Restituisce un testo di ispezione tramite __repr__.
Una stringa viene racchiusa fra virgolette e il ritorno a capo si scrive come barra inversa seguita da n. La rappresentazione resta su una riga e l’originale ha tre caratteri.
Una rappresentazione propria può non essere codice valido.
s = "a\nb"
r = repr(s)
assert len(s) == 3 and chr(92) + "n" in r and "\n" not in r
Esempi
text = "a\nb"
print(repr(text))
print(len(text))
Risultato
'a\nb' 3
Una rappresentazione propria può non essere codice valido.