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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:32:47+00:00 2026-05-20T07:32:47+00:00

Instead of using common OOP, like Java and C# do with their base class

  • 0

Instead of using common OOP, like Java and C# do with their base class Object or object, Python uses special methods for basic behaviour of objects. Python uses __str__ which is used when the object is passed to print:

>>> class Demo:
>>>   def __str__(self):
>>>     return "representation"

>>> d = Demo()
>>> print(d)
representation

The same with len:

>>> class Ruler:
>>>   def __len__(self):
>>>     return 42

>>> r = Ruler()
>>> len(r)
42

What I would expect is something like this:

>>> class Ruler:
>>>   def len(self):
>>>     return 42

>>> r = Ruler()
>>> r.len()
42

What is the reason for using special methods indirectly instead of calling usual methods directly?

  • 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-20T07:32:48+00:00Added an answer on May 20, 2026 at 7:32 am

    The reason for this is explained well in the Python documentation here:

    http://docs.python.org/faq/design.html#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list

    The major reason is history. Functions
    were used for those operations that
    were generic for a group of types and
    which were intended to work even for
    objects that didn’t have methods at
    all (e.g. tuples). It is also
    convenient to have a function that can
    readily be applied to an amorphous
    collection of objects when you use the
    functional features of Python (map(),
    apply() et al).

    In fact, implementing len(), max(),
    min() as a built-in function is
    actually less code than implementing
    them as methods for each type. One can
    quibble about individual cases but
    it’s a part of Python, and it’s too
    late to make such fundamental changes
    now. The functions have to remain to
    avoid massive code breakage.

    (This was answered in the comments, but needs to be shown as a real answer for the sake of future readers.)

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

Sidebar

Related Questions

Basically, I'd like to do the following, only using Common Lisp instead of Python:
I'm using common code in my Activity like this: abstract class CommonCode extends Activity
Instead of using an interface like this: public interface IStartable { void Start(); void
instead of using getParameterByName('Field', PostData) (PostData == $('form').serialize();) I would like to write PostData.Field,
After storing objects of different types in the same container using common parent class
Instead using the google search appliance crawler for index content, im using a query
Instead using of: if ( ! $('#XX').is(':visible) ) Is there a value called invisible
...instead of using the Atom syndication format? Atom is a well-defined , general-purpose XML
Instead of using an external web-based Mercurial host, I want to set one up
I am using jQuery with ASP.NET in a project. Instead of using ASP.NET Ajax,

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.