What is the difference between repr and STR in Python?

Source: Internet
Author: User

The STR () function is meant to return representations of values which are fairly

Human-readable, while repr () is meant to generate representations which can be read

The interpreter (or will force a syntaxerror if there is not equivalent syntax).

Objects which don't have a participant representation for human consumption, STR () will

Return the same value as repr (). incluvalues, such as numbers or structures like lists

And dictionaries, have the same representation using either function. Strings and

Floating point numbers, in particle, have two distinct representations.

 

>>> try: <br/> raise exception (1, 2, 3); <br/> Except t exception as E: <br/> Print (E ); <br/> Print (Repr (e); <br/> Print (STR (e); <br/> Print (E. ARGs); </P> <p> (1, 2, 3) <br/> exception (1, 2, 3) <br/> (1, 2, 3) <br/> (1, 2, 3) <br/> S = 'Hello world' <br/> STR (s) <br/> 'Hello world' <br/> repr (s) <br/> "'Hello world'"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.