最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

在Python中查找最小变量

SEO心得admin67浏览0评论
本文介绍了在Python中查找最小变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一些整数变量,我想找到最小的一个.当我使用时:

I have some integer variables and I want to find smallest one. When I use:

m1 = min(v1, v2, ...)

我得到了最小的值,而不是它的名字.我想知道哪一个最小,不知道它的价值!我该怎么办?

I get the value of the smallest one, not its name. I want to know which one is smallest, not know it's value! How should I do this?

推荐答案

如果索引号有效,则可以执行以下操作:

If the index number will work, you could do this:

# enter variables a = 1 b = 2 c = 3 # place variables in list l = (a,b,c) # get index of smallest item in list X = l.index(min(l)) # to print the name of the variable print(l[X])

X是最小变量的索引号(在这种情况下为0),可以根据需要使用,也可以使用l [X]访问变量名.

X, then, is the index number of the smallest variable (in this case, 0) and can be used as needed, or l[X] could be used to access the variable name.

(但不要像我一样使用小写的"L",通常不认为它是好的样式,因为它很容易被误认为是大写的"i"或数字1).

(But don't use lower case "L" like I did, not usually considered good style 'cuz it can easily be mistaken for upper cas "i" or the number 1).

发布评论

评论列表(0)

  1. 暂无评论