Python repr()
The repr() function will return the printable representation of all information regarding the given object.
Python repr()
The syntax of repr() is:
1
2
repr(object_name)
repr() Parameters
The repr() function only take one parameter as an argument:
- object_name - the name of the object whose information has to be returned.
Let’s check some examples of the python repr() function.
Example 1: How to use the repr() function in python?
1
2
3
4
object_name = "Python"
print(repr(object_name))
Output:
1
2
'Python'
In the above program, we assign a value “Python” to the object_name variable. Then the repr() function returns “Python” or ‘Python’ inside double-quotes.
Rules of repr()
- repr() will return a string representing a given object; if the integer is given, it will return it as a string.
This post is licensed under CC BY 4.0 by the author.