#coding=utf8'''數字類型:數字提供標量貯存和直接訪問。它是不可更改類型,變更數字的值會產生新的對象。Python支持多種數字類型:整型、長整型、布爾型、雙精度浮點型、十進制浮點型和復數。'''def digtalIndroduce(): ''' 創建數值對象并給其賦值 ''' PRint "The first give the variable to value" Int=45 Long=4444444444444L Bool=True Float=3.141592653589793228885555558888 Dicmal=10.25 Complex=25+12.36j print "%d the id:%r" %(Int,id(Int)) print "%r the id:%r" %(Long,id(Long)) print "%r the id:%r" %(Bool,id(Bool)) print "%r the id:%r" %(Float,id(Float)) print "%r the id:%r" %(Dicmal,id(Dicmal)) print "%r the id:%r" %(Complex,id(Complex)) ''' 更新數字對象: 通過給數字對象重新賦值,可以“更新”一個數值對象。 所謂的更新,其實就是生成一個新的數值對象,并得到它的引用。 ''' print "Update the value of the variable" Int+=5 Long=4444L Bool=False Float=3.14188 Dicmal+=10.25 Complex=10+12j print "%d the id:%r" %(Int,id(Int)) print "%r the id:%r" %(Long,id(Long)) print "%r the id:%r" %(Bool,id(Bool)) print "%r the id:%r" %(Float,id(Float)) print "%rthe id:%r" %(Dicmal,id(Dicmal)) print "%r the id:%r" %(Complex,id(Complex)) ''' 刪除數字對象: Python無法真正刪除一個數值對象,僅僅刪除數值對象的一個引用。 刪除對象的引用之后,就不可以再使用這個引用(變量名),除非重新賦值。 否則使用刪除的引用,會引發NameError異常。 ''' print "delete the object reference" del Int,Long,Bool,Float,Dicmal,Complex try: print "%d the id:%r" %(Int,id(Int)) print "%r the id:%r" %(Long,id(Long)) print "%r the id:%r" %(Bool,id(Bool)) print "%r the id:%r" %(Float,id(Float)) print "%rthe id:%r" %(Dicmal,id(Dicmal)) print "%r the id:%r" %(Complex,id(Complex)) except NameError,e: print "NameError:",e '''call the function :digtalIndroduce()'''digtalIndroduce()
新聞熱點
疑難解答