Python基础教程第二版上的代码。
继续嫌解释不够啰嗦,所以自己继续整白(xia)话版。
代码运行效果是这样滴: 两个argu的顺序不能错哦,必须先magnus后template。
magnus存各种会更改变量比如名字。template存不动的模板,然而里面也有些许变量。
magnus:
[name = ‘Jone Wong’]
[email = ‘JWz054@126.com’]
[language = ‘python’]
template:
[import time]
Dear [name],
I would like to learn how to program. I hear you use the [language] language a lot – is it something I should consider?
And, by the way, is [email] your correct email address?
Fooville, [time.asctime()]
接下来是代码解释:
上图5描述不准确,那叫建立正则pattern。
还有个关键点:那个replacement(match)的match,个人会把它看做一种占位,其实就是前面初始化的re.compile这个pattern。