小编Cat*_*ner的帖子

在我的while循环中没有存储值

在以下示例中,@DAYS是月份的日期和条目@DAYS_SINCE_RAIN对应于条目@DAYS,例如$DAYS_SINCE_RAIN[4],自上次下雨以来的天数$DAYS[4].

@DAYS_SINCE_RAIN,有雨的那一天的值为0.我想要出现0的最后一个实例.

#iii. Find the last day of rain in April 2013.
print "#iii. Find the last day of rain in April 2013.\n";
$i=0;
@getday=();

while(@DAYS_SINCE_RAIN[$i]=~ m/0/){
    push @getday, @DAY[$i];
    $i++; 
    if($i=$#DAYS_SINCE_RAIN){
        last;
    }
};

print "@DAYS_SINCE_RAIN";
print "\n day of last rain: @getday[$i] ";
Run Code Online (Sandbox Code Playgroud)

似乎没有存储任何值:(

perl

2
推荐指数
1
解决办法
87
查看次数

为什么这个bool表达式'或'返回True?

我仍在使用bool逻辑.

我有这个片段,我不明白为什么结果出来了.

flag = False
print(flag)
flag = flag or True
print(flag)
Run Code Online (Sandbox Code Playgroud)

你得到:

>>False
>>True
Run Code Online (Sandbox Code Playgroud)

为什么会这样?我不确定这是如何工作的.

是或者应该给你任何表达式为True的实例?

我知道为什么会这样:

check = (7 > 60) or (7 < 10)
print(check)
Run Code Online (Sandbox Code Playgroud)

7小于10,因此检查表达式为True

感谢您的解释.只是想在脑子里研究bool.

python boolean-logic boolean-expression boolean-operations

-3
推荐指数
1
解决办法
74
查看次数