How to Use repr() Function in PythonPython Basics


The repr() function returns printable representations that can be read by the interpreter.

Example

#!/usr/bin/python3
s = 'a+b=C'
print(repr(s))

dict1 = {'cba': 'abc', '321': '123'}
print(repr(dict1))

Output:

'a+b=C'
{'cba': 'abc', '321': '123'}

Syntax

repr(object)

Parameters

object — object whose printable representation has to be returned.

Return Value

It returns a printable representation of the given object.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us