this post was submitted on 24 Apr 2025
48 points (92.9% liked)

Python

7042 readers
109 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] 2 points 11 hours ago (1 children)

Because that's a fundamental aspect of Python. When you're using a language, you should be familiar with the truthiness values. In Python, it's pretty sane:

  • [], {}, set(), "", None, False 0 and related values are all "falesy"
  • everything else is truthy

Basically, if you have non-default values, it's truthy. Why wouldn't you trust basic features of the language?

[โ€“] [email protected] 1 points 9 minutes ago

Because I have to do the is this falsy to what I'm actually interested conversion in my head.

Say ur deep inside some complicated piece of logic and u are trying to understand. Now u have a bunch of assumptions in your head. You should be trying to eliminate as many if these assumptions with good code as possible eg u test ur fail case and return/continue that so u don't need to keep that assumption in ur head.

Say I then come along a if not x then you have to figure out what is x what is the truthiness of its type. If I come across an if len(x) == 0 then I automatically know that x is some collection of objects and I'm testing its emptiness.