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.
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}
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”
In case anyone’s curious:
not() # True str(not()) # 'True' min(str(not())) # 'T' ord(min(str(not()))) # 84 range(ord(min(str(not())))) # range(0, 84) sum(range(ord(min(str(not()))))) # 3486 chr(sum(range(ord(min(str(not())))))) # 'à¶'
You forgot the most important part!
print(chr(3486)) # ඞ
Why is that thing scary?
It looks like the characters from the game Among Us.
It could be an impostor
It could be a monster.
Why does not without a parameter return True? I’m starting to like the fact that I haven’t touched python in a while.
I think it’s because
not()
is equivalent tonot(None)
, and sinceNone
is falsynot(None)
returnsTrue
.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 applynot
to getTrue
. Not having space betweennot
operator and parentheses makes it look like it is a function.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)
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}
I understand that, it makes sense. But why does it not throw an error? The parameter is missing after all.
Actually the explanation is wrong.
not()
is actually
not
is a keyword not a function.Boolean of empty tuple is
False
and thennot
negates it.I explained it better here:
https://lemm.ee/post/61594443/19783421
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”
in J, many other languages, not null is null.
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
God I love python
What kind of dumb language is this?
Python, but this is actually defined and documented behavior.
Python!