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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM