当前第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中缩进是什么
Python脚本怎么执行
Python不支持的数据类型是什么
Python阶乘函数怎么使用
如何用Python代码温度转换?
手机有什么Python编译器
spring boot最核心的3个注解的介绍(附代码)
学习Python需要注意的地方
Python中正确的字符串编码规范
Python怎么输出汉字
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 什么是Python字符串模板