python——print

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

复制代码
-------------------------------------------
-------------------------------------------
字体色     |       背景色     |      颜色描述
-------------------------------------------
30        |        40       |       黑色
31        |        41       |       红色
32        |        42       |       绿色
33        |        43       |       黃色
34        |        44       |       蓝色
35        |        45       |       紫红色
36        |        46       |       青蓝色
37        |        47       |       白色
-------------------------------------------
-------------------------------
显示方式 | 效果 ------------------------------- 0 | 终端默认设置 1 | 高亮显示 4 | 使用下划线 5 | 闪烁 7 | 反白显示 8 | 不可见
-------------------------------
复制代码

例:

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输出时不换行:

如果 python是2.x版本,在语句后加一个英文的逗号 ,
print x,

如果 python是3.x 版本 print不换行参数 end=""
print(x, end="")

例:

print('he'
      ''   #中间回车键换行
      ''
      ''
      'llo',end='')

输出结果:

hello
posted @ 2018-07-10 13:55  cyreaper  阅读(204)  评论(0编辑  收藏  举报