What is the difference between str and repr functions in Python

0 votes
I am new to Python. So basically I want to know the difference between str() function and repr() function because both the functions produce the same output.
Jul 8, 2019 in Python by Neel
• 3,020 points
1,375 views

1 answer to this question.

0 votes
str() is mostly used to create output for end users. repr() is mainly used for debugging and exploring.

For example, if you suspect a string has non-printing characters in it, or a float has a small rounding error, repr() will show you; str() may not be useful in this case

repr() can also be useful for generating literals to paste into your source code.
answered Jul 8, 2019 by Arvind
• 3,040 points

Related Questions In Python

+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 58,090 points
2,059 views
0 votes
5 answers
+2 votes
2 answers

What is the difference between print and return in python?

Return statements end the execution of a ...READ MORE

answered Aug 26, 2019 in Python by anonymous
7,392 views
0 votes
0 answers

What is the difference between isdigit, isnumeric and isdecimal in python?

Can you give examples for each of ...READ MORE

May 31, 2019 in Python by Waseem
• 4,540 points
2,006 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,007 views
0 votes
1 answer
0 votes
1 answer

What is the difference between print and pprint in Python?

As per the documentation,  The pprint module provides a capability ...READ MORE

answered Jul 8, 2019 in Python by Arvind
• 3,040 points
6,326 views
0 votes
1 answer

What is the use of '==' operator in dictionary in Python?

Yes you can use '==' operator to ...READ MORE

answered Jul 24, 2019 in Python by Arvind
• 3,040 points
520 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP