- why would anyone use double underscores
- why not just do
len([1,2,3])?
my question is specifically What do the underscores mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The one reason I’ve had to use
x.__len__()rather thanlen(x)is due to the limitation thatlencan only return anint, whereas__len__can return anything.You might quite reasonably argue that only an integer should be returned, but if the length of your object is greater than
sys.maxsizethen you have no choice except to return alonginstead:This isn’t just a theoretical limitation, I’ve done a fair bit of work with bit containers where (with 32-bit Python) the
lenfunction stops working when the object reaches just 256MB.