鱼C论坛

 找回密码
 立即注册
查看: 2479|回复: 1

求教

[复制链接]
发表于 2017-6-27 21:29:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
!/usr/bin/env python3.5
-- coding: utf-8 --
def area_of_circle(r):
       return 3.1415926  r  r

def sigma_n_sum(n, func):
       total = 0
       for i in range(1, n + 1):
           total += func(i)
       return total

def fun_ori(n):
    return n

def fun_square(n):
    return n ** 2 + 1

print("area is:", area_of_circle(3))
print("sum of %d is %d" %(100, sigma_n_sum(100, fun_ori)))
print("square sum of %d is %d" %(100, sigma_n_sum(100, fun_square)))
我不明白这里面的func是什么意思?为什么可以调用下面两个函数
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-6-27 22:15:14 | 显示全部楼层
你这段代码肯定是不完整的。  func只是def sigma_n_sum 这个函数的形参。
但是函数内部又调用了func(i)   
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-2-22 02:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表