Python[print函数]

下面是 print函数的一种用法,用逗号隔开,可在同一行打印不同类型的数据。
x = input('请你输入被除数:')
y = input('请你输入除数:')
z = float(x)/float(y)
print(x,'/',y,'=',z)

#########################################################################################

>>> help(print) #python查看帮助的其中一种方式

print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.

##############################################################################

print打印倒计时

import time

print("倒计时程序")

for x in range(5,-1,-1):

  mystr = "倒计时" + str(x) + "秒"

  print(mystr,end = "")

  print("\b" * (len(mystr)*2),end = "",flush=True) #\b 退格 (len(mystr)打印len(mystr)字符串长度 1个中文字符 = 2个英文字符(占位),所以*2

  time.sleep(1)

猜你喜欢

转载自www.cnblogs.com/CH-TNT/p/11222565.html