下表列出了所有Python語言支持的賦值運算符。假設(shè)變量a持有10和變量b持有20,則:

例如:
試試下面的例子就明白了所有在Python編程語言可供選擇的賦值運算符:
#!/usr/bin/pythona = 21b = 10c = 0c = a + bprint "Line 1 - Value of c is ", cc += aprint "Line 2 - Value of c is ", c c *= aprint "Line 3 - Value of c is ", c c /= a print "Line 4 - Value of c is ", c c = 2c %= aprint "Line 5 - Value of c is ", cc **= aprint "Line 6 - Value of c is ", cc //= aprint "Line 7 - Value of c is ", c
當(dāng)執(zhí)行上面的程序,它會產(chǎn)生以下結(jié)果:
Line 1 - Value of c is 31Line 2 - Value of c is 52Line 3 - Value of c is 1092Line 4 - Value of c is 52Line 5 - Value of c is 2Line 6 - Value of c is 2097152Line 7 - Value of c is 99864
新聞熱點
疑難解答
圖片精選