Python字符串format_map()

本文介绍了Python 3.2引入的format_map()函数,用于格式化字符串并利用提供的映射中的替换。它与format()函数类似,但直接使用映射,不复制到字典,当映射是dict子类时特别有用。文章通过示例展示了如何使用format_map()以及它与format()的区别,并在映射中键缺失时的行为。
摘要由CSDN通过智能技术生成

python string format_map()

Python string format_map() function returns a formatted version of the string using substitutions from the mapping provided. The substitution arguments are present in the string and identified by curly braces ({ }).


Python字符串format_map()函数使用提供的映射中的替换返回字符串的格式化版本。 替换参数出现在字符串中,并用花括号({})标识。

Python字符串format_map() (Python String format_map())

This function was introduced in Python 3.2. It’s syntax is:

此功能在Python 3.2中引入。 它的语法是:

str.format_map(mapping)

Let’s look at some examples of format_map() function.

我们来看一下format_map()函数的一些示例。

s = 'My name is {name} and I am a {job_title}'

my
  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值