The difference between Python str and repr

Source: Internet
Author: User
Although Str (), repr () and ' operations are very similar in terms of features and functions, the fact that repr () and ' ' are doing exactly the same thing, they return an "official" string representation of an object, which means that in most cases it can be evaluated (using the built-in function eval () ) to get the object back, but Str () is different. STR () is committed to generating an object's readable string representation, and its return results are usually not available for eval () evaluation, but are well suited for print statement output. Again, not all strings returned by REPR () are able to use the eval () built-in function to get the original object.

This means that the repr () output is friendly to Python, and the output of STR () is more user friendly. Even so, in many cases the output of the three is still exactly the same.

Everyone is interested in writing a code comparison below Str,repr and "".
  • 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.