什么是Python字符串模板


当前第2页 返回上一页

下面的示例shell会话用于说明模板字符串对象。

1

>>> from string import Template

1

>>> s = Template('$when, $who $action $what.')

1

>>> s.substitute(when='In the summer', who='John', action='drinks', what='iced tea') 'In the summer, John drinks iced tea.'

1

>>> s.substitute(when='At night', who='Jean', action='eats', what='popcorn') 'At night, Jean eats popcorn.'

1

>>> s.template '$when, $who $action $what.'

1

>>> d = dict(when='in the summer')

以上就是什么是Python字符串模板的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python smtp发送邮件的详细介绍(附代码)

浅谈Python中的排序

Python怎么把转列表为集合

Python中排序算法的实现方法总结(代码)

Python中startx是什么意思

Python装饰器的执行过程实例分析

Python怎么去重

Python画红色五角星的代码是什么

Python中lambda函数的用法介绍(附示例)

Python string、 bytes、 bytearray类型详解

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...