Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3681628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:42:31+00:00 2026-05-19T03:42:31+00:00

I have been reading about repr in Python. I was wondering what the application

  • 0

I have been reading about repr in Python. I was wondering what the application of the output of repr is. e.g.

class A:
 pass

repr(A) ='<class __main__.A at 0x6f570>'

b=A()
repr(b) = '<__main__.A instance at 0x74d78>'

When would one be interested in '<class __main__.A at 0x6f570>' or'<__main__.A instance at 0x74d78>'?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:42:32+00:00Added an answer on May 19, 2026 at 3:42 am

    Sometimes you have to deal with or present a byte string such as

    bob2='bob\xf0\xa4\xad\xa2'
    

    If you print this out (in Ubuntu) you get

    In [62]: print(bob2)
    bob
    

    which is not very helpful to others trying to understand your byte string. In the comments, John points out that in Windows, print(bob2) results in something like bob𤭢. The problem is that Python detects the default encoding of your terminal/console and tries to decode the byte string according to that encoding. Since Ubuntu and Windows uses different default encodings (possibly utf-8 and cp1252 respectively), different results ensue.

    In contrast, the repr of a string is unambiguous:

    In [63]: print(repr(bob2))
    'bob\xf0\xa4\xad\xa2'
    

    When people post questions here on SO about Python strings, they are often asked to show the repr of the string so we know for sure what string they are dealing with.

    In general, the repr should be an unambiguous string representation of the object. repr(obj) calls the object obj‘s __repr__ method. Since in your example the class A does not have its own __repr__ method, repr(b) resorts to indicating the class and memory address.

    You can override the __repr__ method to give more relevant information.


    In your example, '<__main__.A instance at 0x74d78>' tells us two useful things:

    1. that b is an instance of class A
      in the __main__
      namespace,
    2. and that the object resides in
      memory at address 0x74d78.

    You might for instance, have two instances of class A. If they have the same memory address then you’d know they are “pointing” to the same underlying object. (Note this information can also be obtained using id).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading about creating an RPM for Python 2.6.4. In this page:
I've been reading about Skip Lists lately. I have a web application that executes
I have been reading about the differences between Table Variables and Temp Tables and
I have been hearing and reading about Agile for years. I own a book
I have been reading through the C++ FAQ and was curious about the friend
I have been reading about Security of Design . I noticed a tip of
I have been reading about collision detection in games on stackoverflow and other sites.
I have been reading about the continuation passing style programming technique (C# 3.0 implementation).
I have been reading about out of memory conditions on Linux, and the following
I have been reading about the syncroot element but I can't find it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.