In Python, why does Len () write the object in parentheses, while lower () writes the object in front rather than in parentheses?

Source: Internet
Author: User
In the Learning Code Academy small problems encountered, ask the great God advice!

Reply content:

A common design in Python is to use global methods to set up instances of different classes to invoke a method of the same name for different instances, such as ' Repr (o) ' called ' o.__repr__ () ', ' iter (o) ' called ' o.__iter__ () ', ' Len (o ' Call ' o.__len__ () ', but ' o.lower () ' only has meaning to the string, there is no need to design a global lower method to tune it. Len () is a Python built-in Functions, which searches the help document for "built-in Functions". The second lower () is a method of the object, which is used naturally as an object. Lower (). One is the system function, the other is the object method.
  • 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.