How can I count the number of elements in an array, because contrary to logic array.count(string) does not count all the elements in the array, it just searches for the number of occurrences of string.
The method len() returns the number of elements in the list.
myArray = [1, 2, 3] len(myArray)
len is a built-in function that calls the given container object's
__len__ member function to get the number of elements in the object.
Functions encased with double underscores are usually "special methods" implementing one of the standard interfaces in Python (container, number, etc). Special methods are used via syntactic sugar (object creation, container indexing and slicing, attribute access, built-in functions, etc.).
obj.__len__() wouldn't be the correct way of using the special method, but I don't see why the others were modded down so much.