1-讲解动态语言和静态语言的区别:
。。。。python的面向对象更彻底,相比于Java
2-函数和类也是对象,属于python的一等公民:
何为一等公民,主要体现在4点:
1- 赋值给一个变量
2- 可以添加到集合对象中
3- 可以作为参数传递给函数
4- 可以当作函数的返回值
1-可以赋值给一个变量
def fuction():
print('hello')
class Person:
def __init__(self):
print('Decade')
test = fuction # 可以赋值给一个变量
test() # 然后再由他调用
person = Person
person()

2-可以添加到集合对象中
def function():
print('hello')
class Person:
def __init__(self):
print('Decade')
test = []
test.append(function)
test.append(Person)
for i in test:
print(i())

3-可以作为参数传递给参数
def function():
print('hello')
class Person:
def __init__(self):
print('Decade')
def final_attack_rider(n1, n2):
print(n1()) # 调用,并打印返回
print(n2())
final_attack_rider(function, Person)
output3.png
4-可以当作函数的返回值
补充,可以当作函数的返回值其实是python中装饰器实现的原理,我在我的印象笔记中有装饰器的学习笔记。
def function():
print('hello')
def final_attack_rider():
print('final_attack_rider')
return function
test = final_attack_rider() # 调用final_attack_rider,获取返回function,会打印final_attack_rider
test()

网友评论