Enable/Disable icecream module

With ic.disable() and ic.enable(), respectively, the output of ic() can be completely turned off and then turned back on.

Python3




# Python program to enable/disable ic()
from icecream import ic
  
ic.disable()
ic(1990)
ic("Hello World")
ic.enable()
ic("GFG")
ic(2008)


Output:

$ python gfg.py
ic| 'GFG'
ic| 2008

Note: Here lines ic(1990) and ic(“Hello World”) are not getting printed.

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.

Similar Reads

Installation

To install the IceCream module, you need to open up your terminal or command prompt and type the following command:...

Why use IceCream to debug

Let’s look at an example where the average of three values is printed by the Python code....

Python program to print average of three values using ic()

...

Simplest Example

Python3 from icecream import ic    a = 3 b = 11 c = 42    for i in range(80,83):     a = a*i     b = b*i     c = c*i     ans = (ic(a)+ic(b)+ic(c))/3     ic(int(ans))...

Invoking Python Function using icecream module ic()

...

Multiple ways to print ic() in a function

Here’s a basic example of how to use the IceCream ic() function. Any data type and data structure that python print() supports can be used with IceCream ic()....

ic() helps in identifying the block of code that was executed

...

Using includeContext of icecream module

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....

Enable/Disable icecream module

...

Using configureOutput parameter in icecream module

Here are a few different approaches to include ic() in a function to get basically the same result....

Contact Us