this post was submitted on 24 Apr 2025
46 points (92.6% liked)

Python

7041 readers
106 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 3 points 7 hours ago (1 children)

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!

[โ€“] [email protected] 2 points 3 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.