Search notes:

Python: repr

repr(obj) returns a string that usually(?) can be used in an eval(…) statement to get the original object back:
#!/usr/bin/python3

var = {'foo':  42,
       'bar':'baz'
      }

var_repr = repr(var)
print('type(var_repr) = {:s}'.format(str(type(var_repr)))) # type(var_repr) = <class 'str'>

print(var_repr) # {'foo': 42, 'bar': 'baz'}
    
repr_evald = eval(var_repr)

print('type(repr_evald) = {:s}'.format(str(type(repr_evald)))) # type(repr_evald) = <class 'dict'>
                                                                  
for k,v in repr_evald.items():
    print("{:s} = {:s}".format(k, str(v)) )
Github repository about-python, path: /builtin-functions/repr/eval.py

See also

Behind the scenes, repr() calls an object's __repr__ method.
sys.float_repr_style is a string that controls the behaviour of repr() for floats.
Python: Built in functions

Index