I was quietly addicted to the if not syntax, so I'll leave a note.
Reference: https://www.sejuku.net/blog/65070
The not operator in the if statement returns true if the conditional expression is false. This is just an example sentence because I don't understand a little.
Example sentence
x = 10
if not x == 20:
print(True)
else:
print(False)
Execution result
True
Actual usage example
if not len(sys.argv[1:]):
usage()
Looking at this script, "If the argument is not 1 or more (= no argument), use usage () is called." Well, I don't know this.
I was addicted to the following sentence. A combination of and and not. I'm not sure ... if (not listen) and len(target) and port > 0: Is it? if not (listen and len(target) and port > 0): I was worried because I didn't know what it was.
Example sentence
if not listen and len(target) and port > 0:
buffer = sys.stdin.read()
client_sender(buffer)
In conclusion, I agree with this script. not only hangs on listen.
Example sentence
if (not listen) and len(target) and port > 0:
buffer = sys.stdin.read()
client_sender(buffer)
I don't know if this is all, so I wrote some example sentences and confirmed it.
x = 20
y = 20
#Case 1: The result is "No"
if not x == 10 and y == 20
print("Yes")
else:
print("No")
#Case 2: When the evaluation order of the conditional expression is clarified by adding parentheses, the result is "No" as in Case 1.
if (not x == 10) and y == 20
print("Yes")
else:
print("No")
#Case 3: not==not!=I tried it. The result is "No" as in Case 1.
if x != 10 and y == 20
print("Yes")
else:
print("No")
It's pretty embarrassing to leave such an article on Qiita I posted it because I wanted to remember what I was addicted to at that time. In my case, I'm addicted to something like this over and over again.
Recommended Posts