• Clay_pidgin
    link
    fedilink
    English
    arrow-up
    4
    ·
    17 hours ago

    foo = “potatoes!”

    len(foo)

    will give you the number of characters in the string. It’s not a surefire way to find a list at all!

    • sugar_in_your_tea
      link
      fedilink
      arrow-up
      2
      ·
      13 hours ago

      Same with dictionaries, iterators (will consume the iterator!), and anything else that has a length.

      I’ve actually had the string instead of list issue a number of times, because sometimes things get off and it’s hard to track down where things went wrong.

      For this reason, I think type hints are the way to go. Use them consistently w/ a static analysis tool like pyright and you’ll catch a lot of these issues before running into cryptic error messages.