新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonformat_map()
python 中的format_map()函數(shù)創(chuàng)建了一個新的字典,用于返回字典鍵的值。這里 str 是輸入字典的鍵,映射是存儲輸入字典的變量。該函數(shù)用值替換字符串中的所有鍵。

創(chuàng)新互聯(lián)建站服務(wù)項目包括環(huán)縣網(wǎng)站建設(shè)、環(huán)縣網(wǎng)站制作、環(huán)縣網(wǎng)頁制作以及環(huán)縣網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,環(huán)縣網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到環(huán)縣省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
**str.format_map(mapping)** #where mapping is the variable
format_map()參數(shù):
format_map()采用單參數(shù)映射(字典)。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 繪圖 | 映射字典 | 需要 |
format_map()返回值
此方法使用基于映射的替換,使用花括號{}返回字符串的格式化版本。
| 投入 | 返回值 | | 繪圖 | 格式化字符串 |
Python 中format_map()方法示例
示例 format _ map()函數(shù)在 Python 中是如何工作的?
point = {'a':1,'b':-2}
print('{a} '.format_map(point))
point = {'a':1,'b':-2, 'c': 0}
print('{a} {c}'.format_map(point))
輸出:
1 -2
1 -2 0
示例 format _ map()如何與 dict 子類一起工作?
class Coordinate(dict):
def __missing__(self, key):
return key
print('({a}, )'.format_map(Coordinate(a='1')))
print('({a}, )'.format_map(Coordinate(b='2')))
print('({a}, )'.format_map(Coordinate(a='1', b='2')))
輸出:
(1, b)
(a, 2)
(1, 2) 本文標(biāo)題:創(chuàng)新互聯(lián)Python教程:Pythonformat_map()
文章路徑:http://m.5511xx.com/article/dhisoei.html


咨詢
建站咨詢
