this post was submitted on 17 Apr 2025
175 points (92.7% liked)

memes

14397 readers
3066 users here now

Community rules

1. Be civilNo trolling, bigotry or other insulting / annoying behaviour

2. No politicsThis is non-politics community. For political memes please go to !politicalmemes@lemmy.world

3. No recent repostsCheck for reposts when posting a meme, you can only repost after 1 month

4. No botsNo bots without the express approval of the mods or the admins

5. No Spam/AdsNo advertisements or spam. This is an instance rule and the only way to live.

A collection of some classic Lemmy memes for your enjoyment

Sister communities

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Ziglin@lemmy.world 10 points 1 week ago (1 children)

Why does not without a parameter return True? I'm starting to like the fact that I haven't touched python in a while.

[–] LostXOR@fedia.io 23 points 1 week ago (4 children)

I think it's because not() is equivalent to not(None), and since None is falsy not(None) returns True.

[–] takeda@lemm.ee 6 points 1 week ago (1 children)

Are you sure?

I can't test it now, but to me it looks like () is an empty tuple. Python behavior is that for logic operations empty set equals to false. Then we apply not to get True. Not having space between not operator and parentheses makes it look like it is a function.

[–] LostXOR@fedia.io 1 points 1 week ago

I'm pretty sure you're right; that makes more sense.

[–] brb@sh.itjust.works 5 points 1 week ago

God I love python

[–] Ziglin@lemmy.world 5 points 1 week ago (1 children)

Why is literally nothing equivalent to None? Is it because None is the default value of an optional parameter? (If so why oh why is it optional)

[–] spooky2092@lemmy.blahaj.zone 5 points 1 week ago* (last edited 1 week ago) (1 children)

Because nothing isn't something, and something is true. It's base Boolean logic where everything is either true or false. Null/nothing is false.

It's a weird way to think about conditionals, but it makes sense when you use them in real examples. In my case, I use them like this when I need to make sure that a variable has a value. So I can do something like

If(variable){do things with the variable}else{do stuff when the variable doesn't exist}

[–] Ziglin@lemmy.world 1 points 1 week ago (2 children)

I understand that, it makes sense. But why does it not throw an error? The parameter is missing after all.

[–] takeda@lemm.ee 2 points 1 week ago (1 children)

Actually the explanation is wrong.

not()

is actually

not ()

not is a keyword not a function.

Boolean of empty tuple is False and then not negates it.

I explained it better here:

https://lemm.ee/post/61594443/19783421

[–] Ziglin@lemmy.world 1 points 1 week ago

That makes a lot more sense, thanks I did see in the syntax highlighting that it was a keyword but forgot that none of them took parameters.

[–] spooky2092@lemmy.blahaj.zone 0 points 1 week ago

No it's not, "" (a null/empty string) is the parameter. Not every function needs a parameter to be valid, and negation is one of them. Negating nothing is something, so "not()" = "not(null)" = "not(false)" = "true"

[–] humanspiral@lemmy.ca 2 points 1 week ago (1 children)

in J, many other languages, not null is null.

[–] pupbiru@aussie.zone 3 points 1 week ago
a  = null
if not a:
   …

if not a were null then an if that evaluates that would evaluate it as falsy… also if a would evaluate as falsy :/ that’s far weirder behaviour