Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 下划线“_&引用;内循环_Python 3.x - Fatal编程技术网

Python 3.x 下划线“_&引用;内循环

Python 3.x 下划线“_&引用;内循环,python-3.x,Python 3.x,我正在检查黑客等级上的一个解决方案,我正在解决一个问题,要求打印输入中得分第二高的人的姓名,该输入必须首先转换为嵌套列表 我理解代码中的所有逻辑和大部分代码,但为什么在for循环中使用下划线(\)。如果有不同的概念,请解释代码 marksheet = [] for _ in range(0,int(input())): marksheet.append([input(), float(input())]) second_highest = sorted(list(set([marks

我正在检查黑客等级上的一个解决方案,我正在解决一个问题,要求打印输入中得分第二高的人的姓名,该输入必须首先转换为嵌套列表

我理解代码中的所有逻辑和大部分代码,但为什么在for循环中使用下划线(\)。如果有不同的概念,请解释代码

marksheet = []
for _ in range(0,int(input())):
    marksheet.append([input(), float(input())])

second_highest = sorted(list(set([marks for name, marks in marksheet])))[1]
print('\n'.join([a for a,b in sorted(marksheet) if b == second_highest]))

当函数、生成器或元组的返回值被丢弃时,使用下划线作为变量名是一种Python约定


在您的示例中,
for
循环中的代码没有使用由
range(0,int(input())
生成的值,因此使用下划线是有意义的,因为很明显循环并不打算使用它。

尝试用谷歌搜索标题,并在第一页得到了这个结果