[Python] Invert bool value in one line

python beginner's personal remind memo

Edited in response to your indication It is said that it can be inverted and stored in a variable with not without returning. In other words, it was OK below. .. ..

python.py


li = []
result = bool(li)


turned_result = not bool(li)


print('result: ',result)
print('turned_result: ',turned_result)
# result: False
# turned_result: True 


#### Previous one [It can be inverted by returning a return value with not! ](Https://scrapbox.io/amanatsu-knit-note/ [Python] Invert bool value with not at return) and apply it by immediate execution of lambda

python.py


li = []
result = bool(li)


turned_result = (lambda x: not bool(x))(li)


print('result: ',result)
print('turned_result: ',turned_result)
# result: False
# turned_result: True 


I am a beginner with less than 1 year of experience. I would be grateful if you could hear the opinions of seniors, such as better methods and readability.

Recommended Posts

[Python] Invert bool value in one line
Fizzbuzz in Python (in one line)
Make python segfault in one line
Decompose command arguments in one line in Python
String → Bool value conversion in Python Consideration
One liner in Python
Make a rock-paper-scissors game in one line (python)
Shapley value calculation in Python
DMD in Python one dimension
Try LINE Notify in Python
Decrypt one line of code in Python lambda, map, list
Prime number enumeration in one line
I tried Line notification in Python
[Introduction] Insert line breaks in Python 3
Implemented in 1 minute! LINE Notify in Python
[Python] [3D line graph] Multiple data in one graph, axis values in characters
Handle multiple python versions in one jupyter
Line graphs and scale lines in python
Read the file line by line in Python
Read the file line by line in Python
One liner webServer (with CGI) in python
[Python] Read the specified line in the file
Template for creating command line applications in Python
Quadtree in Python --2
Python in optimization
CURL in python
One liner that outputs multiplication tables in Python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Try implementing two stacks in one array in Python
Unittest in python
One liner to 100% CPU1 core usage in Python
Epoch in Python
Discord in Python
Python hand play (one line notation of if)
Sudoku in Python
DCI in Python
quicksort in python
N-Gram in Python
Programming in python
Find the divisor of the value entered in python
Plink in Python
Constant in python
LINE heroku python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Multiple graphs are displayed in one window (python)
Get files, functions, line numbers running in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
The one that displays the progress bar in Python
Constant in python
nCr in Python.
format in python