C和Python之间的赋值有什么区别?

时间:2017-12-21 14:05:10

标签: python c variables recursion fibonacci

A = 0
B = 1

A, B = B, A + B 

运行5次:

Python中B的值将为1,1,3,3,5。 C中B的值为1,1,1,1,1。

有人会向我解释这个吗?

#include <stdio.h>

#define TRUE (1 == 1);
#define FALSE (1 == 0);

int fibonacci(int sequencia);

int main() {
    fibonacci(5);
    return FALSE;
}

int fibonacci(int sequencia) {
    static int antigo = 0;
    static int novo = 1;
    static int copia = 0;

    if (sequencia == 0) {
        return TRUE;
    }

    else {
        printf("%i\n", novo);
    }
    antigo, novo = novo, antigo + novo;
    fibonacci(sequencia - 1);
}
antigo = 0
novo = 1

def fibonacci(sequencia):
    global antigo, novo
    if sequencia != 0:
        print novo

    else:
        return True

    antigo, novo = novo, antigo + novo
    fibonacci(sequencia - 1)

if __name__ == "__main__":
    fibonacci(5)

0 个答案:

没有答案