思考如下代码, 思考一下, 印象更深刻哦!
#include <stdio.h>
int main(void) {
int a, b;
printf("%d\n", (a = 5));
printf("%d\n", 5 > 4);
printf("%d\n", (b = (a = 5)));
b = 4;
printf("%d\n", b + (a = 5 + 10));
}
括号表达式也有返回值?神奇啊, 而且返回的是最终相对左值的值, 结果如下:
5
1
5
19
那么python也这样, 是的, 是个屁!
a = 5
b = 4
c = (a = b + 4)
print(a, b, c)
不好意思, vscode直接报错, /(ㄒoㄒ)/~~
PS C:\Users\13255\Desktop\试验> & C:/My_Tool/python3.7/python.exe c:/Users/13255/Desktop/试验/5.试验.py
File "c:/Users/13255/Desktop/试验/5.试验.py", line 3
c = (a = b + 4)
^
SyntaxError: invalid syntax
值得留意一下, 嘻嘻嘻