以列表形式输出_python格式化输出总结
生活随笔
收集整理的這篇文章主要介紹了
以列表形式输出_python格式化输出总结
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
%
a = 3.14151617 print('The number is %f'%a) #浮點(diǎn)數(shù)輸出,小數(shù)點(diǎn)后保留6位有效數(shù)字 print('The number is %.3f'%a) #浮點(diǎn)數(shù),小數(shù)點(diǎn)后保留3位有效數(shù)字 print('The number is %.3ef'%a) #指數(shù)形式輸出,小數(shù)點(diǎn)后保留3位有效數(shù)字 print('The number is %.3f or %.3f'%(a,a)) print('The number is %d'%a) #十進(jìn)制整數(shù)形式輸出 print('The number is %s'%'a') #字符串形式輸出str.format
print('I love {} and {}'.format('python','C++')) #默認(rèn)順序 print('I love {0} and {1}'.format('python','C++')) #設(shè)置位置 print('I love {0} and {0}'.format('python')) #同上print('I love {name1} and {name2}'.format(name1='python',name2='C++')) #指定參數(shù)lst = ['python','C++'] print('I love {0[0]} and {0[1]}'.format(lst)) # 采用列表方法,不指定參數(shù),0是必須的 print('I love {name[0]} and {name[1]}'.format(name=lst)) #采用列表方法,指定參數(shù)dit = {'name1':'python','name2':'C++'} print('I love {0[name1]} and {0[name2]}'.format(dit)) #采用字典方法,不指定參數(shù),0必須的 print('I love {name[name1]} and {name[name2]}'.format(name=dit)) #采用字典方法,指定參數(shù) print('I love {name1} and {name2}'.format(**dit)) #采用字典放,**dita = 3.141516 print('The number is {:.2f}'.format(a)) #格式轉(zhuǎn)換 print('The number is {:b}'.format(11)) #同上歡迎交流~
總結(jié)
以上是生活随笔為你收集整理的以列表形式输出_python格式化输出总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: cassandra可视化工具_程序员绘图
- 下一篇: git 提交命令_工作总结:Git的学习