小编Adn*_*nan的帖子

C编程-while循环中的逗号运算符

编1:

#include<stdio.h>
 int main()
 {
     int i=0;
     while(i<=8,i++);
     printf("%d",i);
     return 0;
  }
Run Code Online (Sandbox Code Playgroud)

编2:

#include<stdio.h>
 int main()
{
  int i=0;
  while(i++,i<=8);
  printf("%d",i);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

Prog 1的输出为1,而Prog 2的输出为9。

有人可以解释一下这里发生了什么。两种代码有何不同?

c programming-languages comma while-loop

4
推荐指数
1
解决办法
4212
查看次数

参数Parser Python条件要求

我有一个Python程序,它维护一个联系人列表,我希望它通过命令行支持以下选项:

  1. --show ,接受一个字符串参数
  2. --list,不论证
  3. --add,接受一个字符串参数
  4. --number,接受一个int参数
  5. --email,接受一个字符串参数

我需要的是:

prog [--show xyz | --list | --add xyz --number 123 --email abcd@xyz.com ]
Run Code Online (Sandbox Code Playgroud)

我尝试使用subparsers实现它,如下所示:

parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()

subparser1 = subparsers.add_parser('1')
subparser1.add_argument('--show', type=str, help="Shows the contact based on the given name provided as argument")
subparser1.add_argument('--list', action='store_true', help= "Prints all the contacts")

subparser2 = subparsers.add_parser('2')

subparser2.add_argument('--add', type=str, help="Adds a new contact by this name",required=True)
subparser2.add_argument('--number', type=int, help="The Phone Number for the new contact",required=True)
subparser2.add_argument('--email', type=str, help="Email address …
Run Code Online (Sandbox Code Playgroud)

python argparse

4
推荐指数
1
解决办法
144
查看次数

标签 统计

argparse ×1

c ×1

comma ×1

programming-languages ×1

python ×1

while-loop ×1