python 不以科學計數法輸出


#numpy不以科學計數法輸出
np.set_printoptions(suppress=True)
#pandas不以科學計數法輸出,最大顯示無省略號行列【10*10】
pd.set_option('display.max_columns', 10, 'display.max_rows', 10,'display.float_format', lambda x: '%.2f' %x)
#平時不以科學計數法輸出
print("x= {0:.4f}, y = {1:.4f}".format(x,y))
冒號前是變量位置,如果只輸出一個變量可以不寫,即
print("x= {:.4f}".format(x))
冒號后是輸出格式限制,可以不寫,即
print("x= {:}".format(x))

測試代碼如下:
x=10000000000000000000/3
y=11111111111111111111/3
print(x)
print(y)
print("x= {:}".format(x))
print("x= {:.4f}".format(x))
print("x= {0:.4f}, y = {1:.4f}".format(x,y))

輸出如下:

 


免責聲明!

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



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