2018-12-13
阅读量:
806
怎么理解python的装饰器?
以下是有关Python中用于理解装饰器函数的函数的描述。
- 在Python中,我们可以在另一个函数中定义一个函数。
- 在Python中,函数可以作为参数传递给另一个函数(函数也可以返回另一个函数)。
- # A Python program to demonstrate that a function
- # can be defined inside another function and a
- # function can be passed as parameter.
- # Adds a welcome message to the string
- def messageWithWelcome(str):
- # Nested function
- def addWelcome():
- return "Welcome to "
- # Return concatenation of addWelcome()
- # and str.
- return addWelcome() + str
- # To get site name to which welcome is added
- def site(site_name):
- return site_name
- print messageWithWelcome(site("GeeksforGeeks"))
Python装饰器是一种删除冗余的强大工具。






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论