You are viewing a single thread.
View all comments View context
10 points

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

permalink
report
parent
reply
23 points

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

permalink
report
parent
reply
6 points

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.

permalink
report
parent
reply
1 point

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

permalink
report
parent
reply
5 points

God I love python

permalink
report
parent
reply
5 points

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)

permalink
report
parent
reply
5 points
*

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}

permalink
report
parent
reply
2 points

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

permalink
report
parent
reply
3 points
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

permalink
report
parent
reply

memes

!memes@lemmy.world

Create post

Community rules

1. Be civil

No trolling, bigotry or other insulting / annoying behaviour

2. No politics

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

3. No recent reposts

Check for reposts when posting a meme, you can only repost after 1 month

4. No bots

No bots without the express approval of the mods or the admins

5. No Spam/Ads

No 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

Community stats

  • 14K

    Monthly active users

  • 4.4K

    Posts

  • 94K

    Comments