Multiple ways to print ic() in a function
Here are a few different approaches to include ic() in a function to get basically the same result.
Python3
# Python program to understand different # ways to print using ic() from icecream import ic def multiply1(i, j, k): ic(i) ic(j) ic(k) return i * j * k def multiply2(i, j, k): ic(i, j, k) return i * j * k def multiply3(i, j, k): return ic(i) * ic(j) * ic(k) ic(multiply1( 1 , 2 , 3 )) ic(multiply2( 1 , 2 , 3 )) ic(multiply3( 1 , 2 , 3 )) |
Output:
$ python gfg.py ic| i: 1 ic| j: 2 ic| k: 3 ic| multiply1(1, 2, 3): 6 ic| i: 1, j: 2, k: 3 ic| multiply2(1, 2, 3): 6 ic| i: 1 ic| j: 2 ic| k: 3 ic| multiply3(1, 2, 3): 6
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.
Contact Us