Is it possible to print using different colors in ipython's Notebook?

后端 未结 12 1182
孤独总比滥情好
孤独总比滥情好 2020-12-23 09:15

Is it somehow possible to have certain output appear in a different color in the IPython Notebook? For example, something along the lines of:

 print(\"Hello          


        
12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 09:59

    You can use this library termcolor and you can get all other official libraries of python in PyPi.

    1. pip install termcolor
    2. then goto ipython

    Code

    from termcolor import colored
    print(colored('hello', 'red'), colored('world', 'green'))
    print(colored("hello red world", 'red'))
    

    Output:

    hello world
    hello red world
    

    The first argument is what you want to print on console and second argument use that color.

    See the documentation in pypi.python.org for more information

提交回复
热议问题