下表列出了所有Python語言支持的賦值運算符。假設變量a持有10和變量b持有20,則:
例如:
試試下面的例子就明白了所有在Python編程語言可供選擇的賦值運算符:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/usr/bin/python a = 21 b = 10 c = 0 c = a + b print "Line 1 - Value of c is " , c c + = a print "Line 2 - Value of c is " , c c * = a print "Line 3 - Value of c is " , c c / = a print "Line 4 - Value of c is " , c c = 2 c % = a print "Line 5 - Value of c is " , c c * * = a print "Line 6 - Value of c is " , c c / / = a print "Line 7 - Value of c is " , c |
當執(zhí)行上面的程序,它會產生以下結果:
1
2
3
4
5
6
7
|
Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 99864 |