自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

對(duì)Python技巧——代碼效率的實(shí)際應(yīng)用詳解

開發(fā) 后端
Python技巧——代碼效率在實(shí)際的應(yīng)用中你是否有橫多不解的地瓜?如果你在這方面存在很多不懂之處你就可以瀏覽以下的文章。

如果你對(duì)Python技巧——代碼效率的實(shí)際應(yīng)用不是很了解的話,你就可以瀏覽以下的文章對(duì)Python技巧的實(shí)際應(yīng)用有個(gè)更深入的了解,希望你在瀏覽完以下的文章你能從中學(xué)到自己想要的東西。

對(duì)象相等。您認(rèn)為type(a) == type(b)和type(a) is type(b)之間的不同是什么?為什么會(huì)選擇后者?函數(shù)isinstance()與這有什么關(guān)系?

 

 

在例4.1 中我們提供了一段腳本來(lái)演示在運(yùn)行時(shí)環(huán)境使用isinstance() 和 type()函數(shù)。隨后我們討論type()的使用以及怎么將這個(gè)例子移植為改用 isinstance()。運(yùn)行 typechk.py, 我們會(huì)得到以下輸出:

  1. -69 is a number of type: int  
  2. 9999999999999999999999 is a number of type: long  
  3. 98.6 is a number of type: float  
  4. (-5.2+1.9j) is a number of type: complex  
  5. xxx is not a number at all!! 

例4.1 檢查類型(typechk.py)函數(shù)displayNumType() 接受一個(gè)數(shù)值參數(shù),Python技巧中使用內(nèi)建函數(shù)type()來(lái)確認(rèn)數(shù)值的類型(或不是一個(gè)數(shù)值類型)。

  1. #!/usr/bin/env python  
  2. def displayNumType(num):  
  3. print num, 'is',  
  4. if isinstance(num, (int, long, float, complex)):  
  5. print 'a number of type:', type(num).__name__  
  6. else:  
  7. print 'not a number at all!!'  
  8. displayNumType(-69)  
  9. displayNumType(9999999999999999999999L)  
  10. displayNumType(98.6)  
  11. displayNumType(-5.2+1.9j)  
  12. displayNumType('xxx')  

 

 

 以上就是對(duì)Python技巧——代碼效率相關(guān)的內(nèi)容的介紹,望你會(huì)有所收獲。

【編輯推薦】

  1. Python語(yǔ)言功能中的宏編程語(yǔ)言的實(shí)際操作方案介紹
  2. Python unicode ascii編碼在windows中的實(shí)際應(yīng)用
  3. mod_python在性能上要優(yōu)于傳統(tǒng)CGI的緣由
  4. Python中文轉(zhuǎn)換url編碼的實(shí)際操作步驟介紹
  5. Python學(xué)習(xí)入門中的先搭環(huán)境的具體應(yīng)用的方法介紹
責(zé)任編輯:佚名 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-03-17 15:58:08

Python環(huán)境

2010-03-17 14:42:09

Python 文件

2010-03-17 16:27:39

Python矩陣轉(zhuǎn)置

2010-03-17 12:20:15

Python Libr

2010-03-17 14:18:27

Python open

2010-03-05 13:48:24

Python for

2010-03-03 16:25:41

Python字符串顯示

2010-03-01 13:06:49

WCF繼承

2010-03-19 14:59:00

python Stri

2010-03-19 15:16:11

Python代碼

2010-03-29 15:33:18

Oracle EXP

2010-03-17 17:06:10

python腳本語(yǔ)言

2010-03-23 14:54:27

Python目錄文件

2024-10-09 12:18:38

2024-01-16 15:19:29

Python內(nèi)存

2009-12-21 14:49:27

2010-04-27 17:02:18

Oracle EXPL

2010-03-16 14:50:49

Python web框

2010-03-17 15:01:24

Python復(fù)制文件

2010-06-24 14:08:25

Linux Cat命令
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)