Invoking Python Function using icecream module ic()
Here’s an example to use IceCream with the python function. The implementation of ic() for printing the return value of the function is the same as using the python print function.
Python3
# Python program to implement ic() # on functions from icecream import ic def square(i): return i * i ic(square( 4 )) |
Output:
$ python gfg.py ic| square(4): 16
Explanation: Here, ic() prints the function with the argument that is being passed and the return value on the right.
Debugging with ice cream in Python
Do you often use Python print() to debug your code? However, if you want to make a significant improvement, you could use IceCream which would make debugging faster, cleaner, and easier to read. ic(), which is short for IceCream prints both expressions/variable names and their values. ic() is faster to type than print(). The output is highlighted and printed in a structured format. If you want, you can include program context (filename, line number, and parent function) easily. You could effortlessly debug while solving competitive code problems and save a lot of time while debugging.