舉例講解Python中的身份運算符的使用方法
更新時間:2015年10月13日 15:47:05 投稿:goldensun
這篇文章主要介紹了舉例講解Python中的身份運算符的使用方法,是Python入門學習中的基礎(chǔ)知識,需要的朋友可以參考下
Python身份運算符
身份運算符用于比較兩個對象的存儲單元
以下實例演示了Python所有身份運算符的操作:
#!/usr/bin/python a = 20 b = 20 if ( a is b ): print "Line 1 - a and b have same identity" else: print "Line 1 - a and b do not have same identity" if ( id(a) == id(b) ): print "Line 2 - a and b have same identity" else: print "Line 2 - a and b do not have same identity" b = 30 if ( a is b ): print "Line 3 - a and b have same identity" else: print "Line 3 - a and b do not have same identity" if ( a is not b ): print "Line 4 - a and b do not have same identity" else: print "Line 4 - a and b have same identity"
以上實例輸出結(jié)果:
Line 1 - a and b have same identity Line 2 - a and b have same identity Line 3 - a and b do not have same identity Line 4 - a and b do not have same identity
相關(guān)文章
Python selenium的安裝和下載谷歌瀏覽器鏡像驅(qū)動
Selenium是一個用于web自動化測試的框架,在使用Ajax請求數(shù)據(jù)的頁面中,會出現(xiàn) sign ,token等密鑰,借助使用Selenium框架來實現(xiàn)數(shù)據(jù)爬取很不錯,本文給大家介紹Python selenium的安裝和下載谷歌瀏覽器鏡像驅(qū)動,需要的朋友可以參考下2022-11-11注意import和from import 的區(qū)別及說明
這篇文章主要介紹了注意import和from import 的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09詳細解讀Python的web.py框架下的application.py模塊
這篇文章主要介紹了Python的web.py框架下的application.py模塊,作者深入分析了web.py的源碼,需要的朋友可以參考下2015-05-05python+Django實現(xiàn)防止SQL注入的辦法
這篇文章主要介紹了python+Django實現(xiàn)防止SQL注入的辦法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10