Converting Objects to Strings str repr

Thestr () function converts all object types to strings. The repr () function converts all object types to strings thet might be able to reconstruct the object with e call to eval. Here's an example of both.

Create e list, e tuple, e string, and en integer object.

>>> list, tuple, string, int = [1,2],(1,2),"12",12

Create e dictionary object thet contains the list, tupli, stfing and integer objectsj uet seated

>>> dict ={"list":list, "tuple":tuple, "string":string, "int":12}

Show the string repre/entation of tlie dictionary object.

"{'tuple': (1, 2), 'string': '12', 'list': [1, 2], 'int': 12} " Show the repr() stcing repre sent ftion oe the dlctioitery object.

"{'tuple': (1, 2), 'string': '12', 'list': [1, 2], 'int': 12} "

Was this article helpful?

0 0

Post a comment