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 8856301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:19:33+00:00 2026-06-14T14:19:33+00:00

Are repr and str identical on Pythons built-in numeric types ( int , bool

  • 0

Are repr and str identical on Pythons built-in numeric types (int, bool, float, and complex), or are there (esoteric?) situations where the two may yield different results?

Related questions on SO (such as this one) focus on how __repr__ and __str__ may be implemented differently, and return different values for strings, but I can’t find anything on the actual implementation on numbers.

  • 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-06-14T14:19:34+00:00Added an answer on June 14, 2026 at 2:19 pm

    Your primary source of information on this is http://hg.python.org/cpython/file/tip/Objects
    For example, in boolobject.c:

    PyTypeObject PyBool_Type = {
        ...stuff...
    
        bool_repr,                                  /* tp_repr */
    
        ...stuff...
    
        bool_repr,                                  /* tp_str */
    

    so yes, they’re guaranteed to be the same.

    For floats, float_repr is different from float_str and depends on sys.float_repr_style.

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

Sidebar

Related Questions

Is there opportunity to join my types using: str.join() I have my class: class
Are there any security exploits that could occur in this scenario: eval(repr(unsanitized_user_input), {__builtins__: None},
a='''b=ddd''' eval(repr(a)) print str(a) print b Please try to use the code, rather than
I have a document that has two content types: text/xml and text/html. I would
In python, is there a difference between repr and the backquote ` (left of
In this question , it was suggested that calling repr on a dictionary would
In Python 2.x, using backticks to get decimal string from int object is Horrible
Are there any ways to add a simple implementations for __str__ , __eq__ ,
I am trying to derive a class from a python primitive, the float, for
import pickle class TasksError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value)

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.