Explain the role of repr function.

Answer Posted / chaitanya

Python can convert any value to a string by making use of two functions repr() or str().

The str() function returns representations of values which are human-readable, while repr() generates representations which can be read by the interpreter.

repr() returns a machine-readable representation of values, suitable for an exec command.

Following code sniipets shows working of repr() & str() :

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is yield a keyword in python?

443


So, what is an iterator, then?

453


Tell us what is python? What are the benefits of using python?

439


Which is more powerful python or c++?

431


does recursion cause any trouble?

498






How do you sort a list alphabetically in python with sort function?

462


What is setup py in python?

437


What are negative indices?

476


What is file context manager?

483


What is instance method?

447


Is r language hard?

462


What is the difference between 'is' and '==' in python?

487


Does the functions help() and dir() list the names of all the built_in functions and variables? If no, how would you list them?

489


Which databases are supported by python?

480


Why python is popular nowadays?

424