整理Python中的賦值運算符
更新時間:2015年05月13日 12:10:25 投稿:goldensun
這篇文章主要介紹了Python中的賦值運算符,其使用是Python的基本功,需要的朋友可以參考下
下表列出了所有Python語言支持的賦值運算符。假設(shè)變量a持有10和變量b持有20,則:

例如:
試試下面的例子就明白了所有在Python編程語言可供選擇的賦值運算符:
#!/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
當(dāng)執(zhí)行上面的程序,它會產(chǎn)生以下結(jié)果:
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
相關(guān)文章
Python數(shù)據(jù)結(jié)構(gòu)與算法之字典樹實現(xiàn)方法示例
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)與算法之字典樹實現(xiàn)方法,可實現(xiàn)針對單詞出現(xiàn)次數(shù)的統(tǒng)計功能,涉及Python樹結(jié)構(gòu)的定義、遍歷及統(tǒng)計等相關(guān)操作技巧,需要的朋友可以參考下2017-12-12
Python操作SQLite數(shù)據(jù)庫的方法詳解
這篇文章主要介紹了Python操作SQLite數(shù)據(jù)庫的方法,較為詳細的分析了Python安裝sqlite數(shù)據(jù)庫模塊及針對sqlite數(shù)據(jù)庫的常用操作技巧,需要的朋友可以參考下2017-06-06
Python編程語言的35個與眾不同之處(語言特征和使用技巧)
這篇文章主要介紹了Python編程語言的35個與眾不同之處,Python編程語言的語言特征和使用技巧,需要的朋友可以參考下2014-07-07

