當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python String format_map方法用法及代碼示例

Python 的 String.format_map(~) 方法提供字典中的鍵,將返回連接成字符串的相應值。

參數

1. Mapping | Dictionary

返回值

以串聯字符串的形式返回字典中給定鍵的對應值。

例子

基本用法

# The string we will use format_map(~) method on.
our_string = "Welcome {fname} {lname}"
# Dictionary to pass through as an argument to format_map(~)
dictionary = {'fname':'Sky','lname':'Towner'}
# Apply format_map(~) method to our_string
our_string.format_map(dictionary)



'Welcome Sky Towner'

相關用法


注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 Python String | format_map method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。