本文共 516 字,大约阅读时间需要 1 分钟。
函数即变量#示范一:函数名称foo 加了()的意思是调用def foo(): print('in the foo') #函数体foo()可以理解为:函数体 print('in the foo') 是一幢大楼的某个房间;foo就是房间的门牌号码。变量同理,X=1 1是一幢大楼的某个房间;X就是房间的门牌号码。#示范二: 两个函数都存在,正常运行def bar(): print('in the bar')def foo(): print('in the foo') bar()foo()#示范三: 两个函数都存在,正常运行。def foo(): print('in the foo') bar()def bar(): print('in the bar')foo()#示范四: 运行报错,调用foo函数时,bar函数还未加载def foo(): print('in the foo') bar()foo()def bar(): print('in the bar')
有的函数可以不用起名字 比如lambda(匿名函数)
calc = lambda x:x*3
转载地址:http://pblof.baihongyu.com/