lynndotconfig 最近的时间轴更新
lynndotconfig

lynndotconfig

V2EX 第 153213 号会员,加入于 2015-12-28 12:46:01 +08:00
lynndotconfig 最近回复了
2017-02-17 15:21:54 +08:00
回复了 yangsunrise 创建的主题 Python 问一个较基础的问题,关于 Python 语句执行顺序?
@yangsunrise 第一条附言中的的输出应该是 3 和 5 。
2017-02-17 15:15:28 +08:00
回复了 yangsunrise 创建的主题 Python 问一个较基础的问题,关于 Python 语句执行顺序?
@yangsunrise

如果 test=lessthan:
test(arg, res) <==> lessthan(arg, res) <==> (return arg < res) <==>  True or False

如果 test=grtrthan:
tese(arg, res) <==> grtrthen(arg, res) <==> ( return arg > res) <==> True or False

是不明白在 python 中函数名可以作为参数这个问题吗?
2017-02-17 10:16:31 +08:00
回复了 yangsunrise 创建的主题 Python 问一个较基础的问题,关于 Python 语句执行顺序?
def minmax(test, *args):
res = args[0]
for arg in args[1:]:
if test(arg, res):
res = arg
return res


def lessthan(x, y):
return x < y


def grtrthan(x, y):
return x > y

find_less = minmax(lessthan, 5, 6, 7, 8, 9, 4)
find_greater = minmax(grtrthan, 5, 6, 4, 3, 2, 1)
print find_less, find_greater

# ##### Output
# 4 6
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3952 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 04:21 · PVG 12:21 · LAX 21:21 · JFK 00:21
Developed with CodeLauncher
♥ Do have faith in what you're doing.