index in array
数组中的索引
that element if it is not present. The expression has the value 1 (true) if array[index] exists, and
0 (false) if it does not exist.
这个表达式测试是否存在特定的索引条目存在,如果它不存在那么在创建元素时就不会有影响。
这个表达式拥有值1(TRUE)如果ARRAY[INDEX]存在,0(FALSE)如果它不存在。
this statement:
if ("2" in frequencies) print "Subscript \"2\" is present."
Note that this is not a test of whether or not the array frequencies contains an element whose
value is "2". (There is no way to do that except to scan all the elements.) Also, this does not
create frequencies["2"], while the following (incorrect) alternative would do so:
if (frequencies["2"] != "") print "Subscript \"2\" is present."
比如,去测试数组frequencies包含有索引条目“2”,你可以写此条语句:
if ("2" in frequencies) print "Subscript \"2\" is present."
注意:它不是用来测试是否数组frequencies包含一个元素且它的值是“2”。(没有办法去这样
测试,除非扫描所有的元素。)另外,当以下语句(非正确)可选的用来做此事,它不创建
元素frequencies["2"];
本文介绍如何使用数组索引测试特定元素的存在性,不创建不存在的元素,并通过实例演示了如何在代码中实现这一功能。
8085

被折叠的 条评论
为什么被折叠?



