print显示颜色

显示颜色格式:\033[显示方式;字体色;背景色m......[\033[0m]

 
  1. -------------------------------------------
  2. -------------------------------------------
  3. 字体色     |       背景色     |      颜色描述
  4. -------------------------------------------
  5. 30        |        40       |       黑色
  6. 31        |        41       |       红色
  7. 32        |        42       |       绿色
  8. 33        |        43       |       黃色
  9. 34        |        44       |       蓝色
  10. 35        |        45       |       紫红色
  11. 36        |        46       |       青蓝色
  12. 37        |        47       |       白色
  13. -------------------------------------------
  14. -------------------------------
  15. 显示方式     |      效果
  16. -------------------------------
  17. 0           |     终端默认设置
  18. 1           |     高亮显示
  19. 4           |     使用下划线
  20. 5           |     闪烁
  21. 7           |     反白显示
  22. 8           |     不可见
  23. -------------------------------
例:
  1. print('This is a \033[1;35m test \033[0m!')print('This is a \033[1;32;43m test \033[0m!')print('\033[1;33;44mThis is a test !\033[0m')
输出结果:
 

print输出时不换行:

  1. 如果 python2.x版本,在语句后加一个英文的逗号 ,
  2. print x,
  3. 如果 python3.x 版本 print不换行参数 end=""
  4. print(x, end="")
例:
  1. print('he'
  2.       ''   #中间回车键换行
  3.       ''
  4.       ''
  5.       'llo',end='')
输出结果:
  1. hello

 

 

posted @ 2018-04-26 11:26  攻城獅  阅读(460)  评论(0编辑  收藏  举报