About 51 results
Open links in new tab
  1. How do I get the number of elements in a list (length of a list) in Python?

    Nov 11, 2009 · 28 Besides len you can also use operator.length_hint (requires Python 3.4+). For a normal list both are equivalent, but length_hint makes it possible to get the length of a list-iterator, …

  2. python - Difference between len () and .__len__ ()? - Stack Overflow

    Well, len(s) is a built-in Python method which returns the length of an object. Now __len__() is a special method that is internally called by len(s) method to return the length of an object.

  3. How to find length of digits in an integer? - Stack Overflow

    Worth noting for all the answers saying to use len(str(n)), in newer versions of Python this will break for integers with over 4300 digits because converting the full binary into base 10 is very slow and had …

  4. Why does Python code use len() function instead of a length method?

    Oct 26, 2008 · The protocol in Python is to implement this method on objects which have a length and use the built-in len() function, which calls it for you, similar to the way you would implement __iter__() …

  5. Why we use range (len) in for loop in python? - Stack Overflow

    Nov 18, 2018 · I have started learning python and now learning python for loop. I am using online source to learn python. But i am little but confused about for loop. The output of list = ["geeks", "for", "ge...

  6. python - Using len () and def __len__ (self): to build a class - Stack ...

    Feb 27, 2013 · The len() function will use the __len__ method if present to query your object for it's length. The normal API people expect to use is the len() method, using a .len attribute instead would …

  7. How to get the size (length) of a string in Python

    "what function can i use to calculate the size of the string"? What tutorial are you using to learn Python? Please update the question with some information on where and how you're learning Python.

  8. python 3.x - How to use the len () in an if statement - Stack Overflow

    Mar 23, 2019 · I am defining a function, standard_deviation that consumes a list of numbers and returns a float representing their standard deviation. I need to use the len function to return None if the list has...

  9. python 3.x - Difference between len and size - Stack Overflow

    Aug 28, 2019 · But len() will return 5, because the number of elements in higher order list (or 1st dimension is 5). According to your question, len() and numpy.size() return same output for 1-D arrays …

  10. python - Why is the use of len (SEQUENCE) in condition values ...

    Mar 30, 2017 · len doesn't know the context in which it is called, so if computing the length means traversing the entire sequence, it must; it doesn't know that the result is just being compared to 0. …