python 2.4以后,增加了@符號修飾函數對函數進行修飾,python3.0/2.6又增加了對類的修飾。
$ 在正則表達式中,匹配一個字符串的末尾。(參考http://www.runoob.com/python/python-reg-expressions.html)
@符號是裝飾器的語法糖,在定義函數的時候使用,避免再一次賦值操作(具體請參考https://blog.csdn.net/yjreset/article/details/79329979)
import time def time(func): print(time.ctime()) return func() @time # 從這里可以看出@time 等價於 time(xxx()),但是這種寫法你得考慮python代碼的執行順序 def xxx(): print('Hello world!')
運行結果:
Wed Jul 26 23:01:21 2017 Hello world!
