Simplest Example
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().
Python3
# Python program to print different # types of datatypes # and data structures using ic() from icecream import ic NUMBER = 2008 FLOAT = 95.47 BOOLEAN = True STRING = "GFG" LIST = [ 1 , 2 , 3 , 4 , 5 ] DICT = { "gfg" : "w3wiki" , "founder" : "Sandeep Jain" , } ic( 123 ) ic(NUMBER) ic( FLOAT ) ic(BOOLEAN) ic(STRING) ic( LIST ) ic( DICT ) |
Output
ic| 123
ic| NUMBER: 2008
ic| FLOAT: 95.47
ic| BOOLEAN: True
ic| STRING: ‘GFG’
ic| LIST: [1, 2, 3, 4, 5]
ic| DICT: {‘founder’: ‘Sandeep Jain’, ‘gfg’: ‘w3wiki’}
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