

{"id":36551,"date":"2018-11-25T10:06:00","date_gmt":"2018-11-25T04:36:00","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=36551"},"modified":"2026-04-14T14:40:49","modified_gmt":"2026-04-14T09:10:49","slug":"python-repr-function","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-repr-function\/","title":{"rendered":"Python repr Function With Example | repr vs str in Python"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Talking of built-in functions in Python, let\u2019s take one more. Today, we will talk about Python repr, concluding with some examples to drive the point home. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we will discuss Python str vs repr. Moreover, we will see working with class objects.\u00a0<\/span><\/p>\n<p>So, let&#8217;s start!!!<\/p>\n<h3>What is repr() in Python?<\/h3>\n<p>The repr() function in Python returns the \u201cofficial\u201d string form of an object, aimed at developers. When you print that string, you often get something you could paste back into Python to rebuild the object (at least in theory).<\/p>\n<p>For basic types, repr(5.0) outputs &#8216;5.0&#8217;, and repr(&#8220;hi&#8221;) yields &#8220;&#8216;hi'&#8221; with quotes included. Collections show square or curly brackets, making nested structures clear during debugging sessions.<\/p>\n<p><span style=\"font-weight: 400\">Let\u2019s ask the IDLE.<\/span><\/p>\n<div id=\"attachment_36559\" style=\"width: 502px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/help.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-36559\" class=\"size-full wp-image-36559\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/help.png\" alt=\"Python repr\" width=\"492\" height=\"159\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/help.png 492w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/help-150x48.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/help-300x97.png 300w\" sizes=\"auto, (max-width: 492px) 100vw, 492px\" \/><\/a><p id=\"caption-attachment-36559\" class=\"wp-caption-text\">What is Python repr Function<\/p><\/div>\n<p><span style=\"font-weight: 400\">This tells us five things:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">repr() is a built-in function<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">repr() takes an object<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">repr() returns the canonical string representation of this object<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">It has the following syntax:<\/span><\/li>\n<\/ul>\n<p><strong>repr(obj, \/)<\/strong><\/p>\n<ul>\n<li><span style=\"font-weight: 400\">It is true for many object types and most builtins that eval(repr(obj))=obj<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Now, what does this last statement mean?<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; s='Hello'\r\n&gt;&gt;&gt; eval(repr(s))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Hello&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; s<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;Hello&#8217;<span style=\"font-weight: 400\">What about an integer?<\/span><\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; x=7\r\n&gt;&gt;&gt; eval(repr(x))==x<\/pre>\n<p><span style=\"font-weight: 400\">True. According to the official Python documentation, repr() returns a string that contains a printable representation of an object. <\/span><\/p>\n<p><span style=\"font-weight: 400\">For most types in Python, this will give you a string that yields an object with the same value as when we pass it to eval(). For a few other types, it returns a string delimited in angle brackets. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This holds the type of object and other information, like the name and address of that object.<\/span><\/p>\n<p><span style=\"font-weight: 400\">To us, this is the repr() function. To Python, this is a class that controls what it returns for its instances via the __repr__() magic method.<\/span><\/p>\n<h3>Python repr Example<\/h3>\n<p><span style=\"font-weight: 400\">Let\u2019s get to an example of the Python repr function.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; msg='Hello, world!'\r\n&gt;&gt;&gt; repr(msg)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>\u201c\u2018Hello, world!\u2019\u201d<\/p>\n<\/div>\n<p>A closer look at this tells us this returns \u2018Hello, world!\u2019 within double quotes. If we pass this back to eval, it gives us:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; eval(\"'Hello, world!'\")<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;Hello, world!&#8217;<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">This wouldn\u2019t work:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; eval('Hello, world!')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#16&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>eval(&#8216;Hello, world!&#8217;)<\/p>\n<p>File &#8220;&lt;string&gt;&#8221;, line 1<\/p>\n<p>Hello, world!<\/p>\n<p>^<\/p>\n<p>SyntaxError: unexpected EOF while parsing<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">This is because we don\u2019t have a variable with that name (Hello, world!)<\/span><\/p>\n<h3>Working With Class Objects<\/h3>\n<p><span style=\"font-weight: 400\">We said repr() internally makes a call to the __repr__() method. Let\u2019s try this with one of our own classes.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class Color:\r\n       color='orange'\r\n       def __repr__(self):\r\n              return repr(self.color)\r\n&gt;&gt;&gt; o=Color()\r\n&gt;&gt;&gt; repr(o)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8220;&#8216;orange'&#8221;<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">Here, we override the __repr__() method to get it to do what we want. When we say the word override, note that Color already has an __repr__() method. This is because it inherits from the <\/span><i><span style=\"font-weight: 400\">object<\/span><\/i><span style=\"font-weight: 400\"> class, and <\/span><i><span style=\"font-weight: 400\">object<\/span><\/i><span style=\"font-weight: 400\"> has an __repr__() method.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; issubclass(Color,object)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>True<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; dir(object)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>[&#8216;__class__&#8217;, &#8216;__delattr__&#8217;, &#8216;__dir__&#8217;, &#8216;__doc__&#8217;, &#8216;__eq__&#8217;, &#8216;__format__&#8217;, &#8216;__ge__&#8217;, &#8216;__getattribute__&#8217;, &#8216;__gt__&#8217;, &#8216;__hash__&#8217;, &#8216;__init__&#8217;, &#8216;__init_subclass__&#8217;, &#8216;__le__&#8217;, &#8216;__lt__&#8217;, &#8216;__ne__&#8217;, &#8216;__new__&#8217;, &#8216;__reduce__&#8217;, &#8216;__reduce_ex__&#8217;, &#8216;__repr__&#8217;, &#8216;__setattr__&#8217;, &#8216;__sizeof__&#8217;, &#8216;__str__&#8217;, &#8216;__subclasshook__&#8217;]<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">Remember when in the beginning, we said repr returns a string in angle brackets for some types? Let\u2019s see how and where.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class Orange:\r\n       def __init__(self,color,size):\r\n               self.color=color\r\n               self.size=size\r\n&gt;&gt;&gt; o=Orange('orange',7)\r\n&gt;&gt;&gt; o<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&lt;__main__.Orange object at 0x02C6C1D0&gt;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; print(o)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&lt;__main__.Orange object at 0x02C6C1D0&gt;<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">These are strings with the class name and the id of the object instance(its memory address in CPython). To print this better, we make use of the information that the print() function makes a call to the __str__ dunder\/ method:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class Orange:\r\n\tdef __init__(self,color,size):\r\n                self.color=color\r\n                self.size=size\r\n\tdef __str__(self):\r\n                return f'I am {self.size} and {self.color}'\r\n&gt;&gt;&gt; o=Orange('orange',7)\r\n&gt;&gt;&gt; o<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&lt;__main__.Orange object at 0x02D40E70&gt;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; print(o)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>I am 7 and orange<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">That was pretty cool! In Java, we would use the toString() method for this.<\/span><\/p>\n<h3>str() vs repr() in Python<\/h3>\n<p><span style=\"font-weight: 400\">The __str__() and __repr__() methods both return strings. So what sets them apart?<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The goal of __repr__ is to be unambiguous, and that of __str__ is to be readable.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">__repr__ is kind of official and __str__ is somewhat informal.<\/span><\/li>\n<\/ul>\n<p><strong>Disadvantages of str():<\/strong><\/p>\n<ul>\n<li><strong>Hides details:<\/strong> To look clean and easy to understand, it hides the data type.<\/li>\n<li><strong>Cannot rebuild:<\/strong> once the code is extracted from str(), it cannot be easily turned back into the original code.<\/li>\n<\/ul>\n<p><strong>Disadvantage of repr():<\/strong><\/p>\n<ul>\n<li><strong>Security risks:<\/strong> Repr can sometimes also show some sensitive information like passwords or keys in error messages or logs.<\/li>\n<li><strong>Difficult to understand:<\/strong> It can create a mess as it tries to display the data, making it hard to find information immediately.<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Take an example to ensure you understand the difference:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; s='Hello'\r\n&gt;&gt;&gt; print(str(s))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Hello<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; print(repr(s))<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;Hello&#8217;<\/p>\n<\/div>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The <\/span><i><span style=\"font-weight: 400\">print<\/span><\/i><span style=\"font-weight: 400\"> statement and <\/span><i><span style=\"font-weight: 400\">str()<\/span><\/i><span style=\"font-weight: 400\"> function make a call to __str__, but repr() makes on to __repr__.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Any string at the interpreter prompt makes a call to __str__(), but an object at the prompt makes a call to __repr__().<\/span><\/li>\n<\/ul>\n<p><strong>Want to do preparation for Python Interview<\/strong> &#8211;<strong><a href=\"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/\"> Click Here &gt;&gt;&gt;<\/a><\/strong><\/p>\n<p><span style=\"font-weight: 400\">Take a look:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; str(3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;3&#8217;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; repr(3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;3&#8217;<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">They appear the same. Okay, now take a look at this one:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; import datetime\r\n&gt;&gt;&gt; t=datetime.datetime.now()\r\n&gt;&gt;&gt; str(t) #Readable<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;2018-09-07 17:33:24.261778&#8217;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; repr(t)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;datetime.datetime(2018, 9, 7, 17, 33, 24, 261778)&#8217;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; t<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>datetime.datetime(2018, 9, 7, 17, 33, 24, 261778)<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">Using this \u2018official\u2019 representation, we can reconstruct the object, but not with what str() gives us:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; eval('datetime.datetime(2018, 9, 7, 17, 33, 24, 261778)')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>datetime.datetime(2018, 9, 7, 17, 33, 24, 261778)<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; eval('2018-09-07 17:33:24.261778')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#56&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>eval(&#8216;2018-09-07 17:33:24.261778&#8217;)<\/p>\n<p>File &#8220;&lt;string&gt;&#8221;, line 1<\/p>\n<p>2018-09-07 17:33:24.261778<\/p>\n<p>^<\/p>\n<p>SyntaxError: invalid token<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">Let\u2019s take another example.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class demo:\r\n       def __init__(self,a,b):\r\n              self.a=a\r\n              self.b=b\r\n       def __repr__(self):\r\n              return '__repr__ for demo'\r\n       def __str__(self):\r\n              return '__str__ for demo'\r\n&gt;&gt;&gt; d=demo(3,4)\r\n&gt;&gt;&gt; d<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>__repr__ for demo<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; print(d)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>__str__ for demo<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; str(d)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;__str__ for demo&#8217;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; repr(d)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;__repr__ for demo&#8217;<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; f'{d}'<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;__str__ for demo&#8217;<\/p>\n<\/div>\n<h3>Python Interview Questions on repr Functions<\/h3>\n<p>1. What is the repr function in Python?<\/p>\n<p>2. What is the difference between repr and str in Python?<\/p>\n<p>3. What does repr stand for in Python?<\/p>\n<p>4. What is the use of the repr function in Python?<\/p>\n<p>5. Give an example of the Python repr function.<\/p>\n<h3><span style=\"font-weight: 400\">Conclusion\u00a0<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The interactive interpreter uses repr() too in giving you the output of your expression:<\/span><\/p>\n<p><b>result=expr; if result is not None: print repr(result)<\/b><\/p>\n<p><span style=\"font-weight: 400\">Hence, in this Python repr tutorial, we discussed the meaning of repr in Python. Also, we looked at Python repr example and working with class objects. Moreover, we saw str vs repr in Python. <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Talking of built-in functions in Python, let\u2019s take one more. Today, we will talk about Python repr, concluding with some examples to drive the point home. Also, we will discuss Python str vs repr.&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":36564,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[16753,10814,16756,16752,36648,36649,16755,16754],"class_list":["post-36551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-python-__repr__","tag-python-repr","tag-python-repr-example","tag-python-repr-function","tag-repr","tag-repr-function-in-python","tag-str-vs-repr-in-python","tag-what-is-repr"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python repr Function With Example | repr vs str in Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about Python repr function with syntax and Example, str vs repr in Python, working with class objects in Python and many more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-repr-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python repr Function With Example | repr vs str in Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about Python repr function with syntax and Example, str vs repr in Python, working with class objects in Python and many more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-repr-function\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-11-25T04:36:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-14T09:10:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/Python-repr-Function-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python repr Function With Example | repr vs str in Python - DataFlair","description":"Learn about Python repr function with syntax and Example, str vs repr in Python, working with class objects in Python and many more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-repr-function\/","og_locale":"en_US","og_type":"article","og_title":"Python repr Function With Example | repr vs str in Python - DataFlair","og_description":"Learn about Python repr function with syntax and Example, str vs repr in Python, working with class objects in Python and many more.","og_url":"https:\/\/data-flair.training\/blogs\/python-repr-function\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-11-25T04:36:00+00:00","article_modified_time":"2026-04-14T09:10:49+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/Python-repr-Function-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python repr Function With Example | repr vs str in Python","datePublished":"2018-11-25T04:36:00+00:00","dateModified":"2026-04-14T09:10:49+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/"},"wordCount":1004,"commentCount":2,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/Python-repr-Function-01.jpg","keywords":["python __repr__","Python repr","Python repr example","python repr function","repr","repr() function in python","str vs repr in Python","What is repr()"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-repr-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/","url":"https:\/\/data-flair.training\/blogs\/python-repr-function\/","name":"Python repr Function With Example | repr vs str in Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/Python-repr-Function-01.jpg","datePublished":"2018-11-25T04:36:00+00:00","dateModified":"2026-04-14T09:10:49+00:00","description":"Learn about Python repr function with syntax and Example, str vs repr in Python, working with class objects in Python and many more.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-repr-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/Python-repr-Function-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/09\/Python-repr-Function-01.jpg","width":1200,"height":630,"caption":"Python repr Function With Example"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-repr-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python repr Function With Example | repr vs str in Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/36551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=36551"}],"version-history":[{"count":18,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/36551\/revisions"}],"predecessor-version":[{"id":147605,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/36551\/revisions\/147605"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/36564"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=36551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=36551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=36551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}