小编ava*_*ans的帖子

Why does this print statement using a Python f-string output double parentheses?

In the following code I output the range of values which I can use to index the list lst. However, due to some oddity of Python's format literals the output contains two opening and two closing parentheses instead of one. I don't see what's wrong with my format string. I just put all expressions which should be substituted in curly braces. The rest should not be substituted.

lst = [1,2,3,4,5,6]
print(f"range({-len(lst), len(lst)})")
> range((-6, 6))
Run Code Online (Sandbox Code Playgroud)

python parentheses python-3.x f-string

5
推荐指数
1
解决办法
132
查看次数

Initialization of variables from within the definition by referencing the type or a variable of that type

Is such heavy use of backreferencing a declaration from the initialization code covered by at least one of the standards (C99-current) or is it a gcc extension? All the member initialization terms have in common that they either reference the type or a member/variable of that type from within the definition of the type.

#include <stddef.h>
#include <stdlib.h>

struct node{
    int size;
    int offset;
    int *ptr;
    struct node *this;
} s = {sizeof(s), offsetof(struct node, offset), &s.offset, &s};

int main(void){ …
Run Code Online (Sandbox Code Playgroud)

c initialization declaration definition

4
推荐指数
2
解决办法
56
查看次数

C 循环直到给出 0

我正在尝试创建一个循环,让用户逐个输入数字并计算所有这些数字的总和,直到用户输入 0 作为输入。但是,我的代码只运行一次,然后就停止了。

#include <stdio.h>

int main(void) {
    int i = 0;
    int num;
    int total = 0;

    printf("Give me a number \n");
    scanf("%d", num);
    
    if(num < 0 && num > 0){
        printf("Give me a number \n");
        scanf("%d", num);
        total = total + num;
        i = i + 1;
    }

    printf("The total is %d", total);
}
Run Code Online (Sandbox Code Playgroud)

c loops for-loop while-loop

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