程序返回条件的0和1

 

001、在linux中如果程序正常执行,则返回0,错误执行返回非0值

 

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
sf
ab
35
34543
[root@PC1 test]# grep "a" a.txt
ab
[root@PC1 test]# echo $?
0
[root@PC1 test]# grep "x" a.txt
[root@PC1 test]# echo $?
1

 

 

002、在c、python中,False为0, True为非0

a、c中

01、

[root@PC1 test]# ls
test.c
[root@PC1 test]# cat test.c
#include <stdio.h>

int main(void)
{
        if(1)
        {
                puts("pass");
        }

        return 0;
}
[root@PC1 test]# gcc test.c -o kkk
[root@PC1 test]# ls
kkk  test.c
[root@PC1 test]# ./kkk
pass

 

02、

[root@PC1 test]# ls
test.c
[root@PC1 test]# cat test.c
#include <stdio.h>

int main(void)
{
        if(0)
        {
                puts("pass");
        }

        return 0;
}
[root@PC1 test]# gcc test.c -o kkk
[root@PC1 test]# ls
kkk  test.c
[root@PC1 test]# ./kkk
[root@PC1 test]#

 

 

 

b、

>>> False == 0
True
>>> False == 1
False
>>> True == 0
False
>>> True == 1
True
>>> True == 2
False

 。

 

posted @ 2024-07-30 14:49  小鲨鱼2018  阅读(2)  评论(0编辑  收藏  举报