Tag: metasyntacticvariables

下划线_作为Python中的variables名

彼得·诺维格(Peter Norvig)撰写了一篇文章,描述了通过结合确定性逻辑运算和智能遍历可能解决scheme来解决数独谜题 (甚至是最困难的问题)的程序 。 后者是recursion地完成的; 这里是该函数( 来源 ): def search(values): "Using depth-first search and propagation, try all possible values." if values is False: return False ## Failed earlier if all( len( values[s]) == 1 for s in squares): return values ## Solved! ## Chose the unfilled square s with the fewest possibilities _,s = min( […]

Python中单个下划线“_”variables的用途是什么?

在这个代码中_之后是什么意思? if tbh.bag: n = 0 for _ in tbh.bag.atom_set(): n += 1