I read this article and found it very useful, so I would like to share it.
Let's assume the following code.
num1 = 30
num2 = 40
print(num1)
print(num2)
The output is
30
40
It will be. Now, by looking at the output above, can you quickly tell whether 30
or 40
corresponds to num1
or num2
?
As long as there are few output variables, this does not seem to be a problem, but when it comes to 5, it becomes a little troublesome.
For the time being, the solution is as follows.
num1 = 30
num2 = 40
print('num1', num1)
print('num2', num2)
The output is
num1 30
num2 40
Certainly, the correspondence between variable names and variable values is easier to understand than in the original code. However, the problem is that writing the code is cumbersome.
The solution to the above problem is the python library Icecream
.
Installation can be done with pip
.
pip install icecream
from icecream import ic
num1 = 30
num2 = 40
ic(num1)
ic(num2)
The output is
ic| num1: 30
ic| num2: 40
Very simple and nice! This is not the only convenience of Icecream. You can use functions and conditional branching. If you are interested, please check here.
Recommended Posts