新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python使用f格式化字符串
1、若要格式化字符串,可在字符串開始引號前添加f或F。

創(chuàng)新互聯(lián)專注于河西網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供河西營銷型網(wǎng)站建設(shè),河西網(wǎng)站制作、河西網(wǎng)頁設(shè)計(jì)、河西網(wǎng)站官網(wǎng)定制、微信小程序開發(fā)服務(wù),打造河西網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供河西網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
2、通過這種方式,我們可以直接中引入變量值,只需將變量放在{ 和 }之間。
>>> year = 2016
>>> event = 'Referendum'
>>> f'Results of the {year} {event}'
'Results of the 2016 Referendum'將python變量放入{}外,還可將函數(shù)放入{}:
>>> import math
>>> print(f'The value of pi is approximately {math.pi:.3f}.')
The value of pi is approximately 3.142.以上就是python使用f格式化字符串的方法,希望對大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
當(dāng)前題目:創(chuàng)新互聯(lián)Python教程:python使用f格式化字符串
文章URL:http://m.fisionsoft.com.cn/article/ccceshs.html


咨詢
建站咨詢
