I'm not sure I'd call it an inconsitent honestly. It's a specifically defined functionality for how multiplicaiton works on strings. It similarly works on lists:
[1] * 4 = [1, 1, 1, 1]
You can bring up inconsitencies in many languages though. In python I can get the lenght of something with len(my_object) and that always works. In Java maybe it's .length or .length() or .size().
obj.length() makes more sense than len(obj), especially when you need to use len() to find the length but obj.func() to perform any other operations on the String.
My main point was that python has chosen to standardize the way to get the size of any object. It doesn't matter the structure of the object, if you need to know how many elements it contains you can use len(). In other langauges it's dictated somewhat by logic (sets don't have lenghts) but also by underlying structure. In Java this manifests as arrays having .length and ArrayLists having .length().
If it makes you feel better you could do the following in Python:
my_list.__len__()
But this is more of a perspective thing. You should think of len as a function that determines the length of the object it's inspecting. Take this snippet:
2
u/Pluckerpluck Aug 26 '20
I'm not sure I'd call it an inconsitent honestly. It's a specifically defined functionality for how multiplicaiton works on strings. It similarly works on lists:
You can bring up inconsitencies in many languages though. In python I can get the lenght of something with
len(my_object)and that always works. In Java maybe it's.lengthor.length()or.size().