[python_Day2]

来源:http://www.cnblogs.com/loveclear/archive/2016/08/13/5767245.html
-Advertisement-
Play Games

對象,常見數據類型與序列的內部功能,collections模塊 ...


摘要:

對象

對於python來說,一切事物都是對象,對象基於類創建:

 

 

註:查看對象相關成員 var,type,dir

基本數據類型和序列

int內部功能

  1 class int(object):
  2     """
  3     int(x=0) -> integer
  4     int(x, base=10) -> integer
  5     
  6     Convert a number or string to an integer, or return 0 if no arguments
  7     are given.  If x is a number, return x.__int__().  For floating point
  8     numbers, this truncates towards zero.
  9     
 10     If x is not a number or if base is given, then x must be a string,
 11     bytes, or bytearray instance representing an integer literal in the
 12     given base.  The literal can be preceded by '+' or '-' and be surrounded
 13     by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
 14     Base 0 means to interpret the base from the string as an integer literal.
 15     >>> int('0b100', base=0)
 16     4
 17     """
 18     def bit_length(self): # real signature unknown; restored from __doc__
 19         #返回該數字最少二進位位數
 20         """
 21         int.bit_length() -> int
 22         
 23         Number of bits necessary to represent self in binary.
 24         >>> bin(37)
 25         '0b100101'
 26         >>> (37).bit_length()
 27         6
 28         """
 29         return 0
 30 
 31     def conjugate(self, *args, **kwargs): # real signature unknown
 32         """ Returns self, the complex conjugate of any int. """
 33         pass
 34 
 35     @classmethod # known case
 36     def from_bytes(cls, bytes, byteorder, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
 37         """
 38         int.from_bytes(bytes, byteorder, *, signed=False) -> int
 39         
 40         Return the integer represented by the given array of bytes.
 41         
 42         The bytes argument must be a bytes-like object (e.g. bytes or bytearray).
 43         
 44         The byteorder argument determines the byte order used to represent the
 45         integer.  If byteorder is 'big', the most significant byte is at the
 46         beginning of the byte array.  If byteorder is 'little', the most
 47         significant byte is at the end of the byte array.  To request the native
 48         byte order of the host system, use `sys.byteorder' as the byte order value.
 49         
 50         The signed keyword-only argument indicates whether two's complement is
 51         used to represent the integer.
 52         """
 53         pass
 54 
 55     def to_bytes(self, length, byteorder, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
 56         """
 57         int.to_bytes(length, byteorder, *, signed=False) -> bytes
 58         
 59         Return an array of bytes representing an integer.
 60         
 61         The integer is represented using length bytes.  An OverflowError is
 62         raised if the integer is not representable with the given number of
 63         bytes.
 64         
 65         The byteorder argument determines the byte order used to represent the
 66         integer.  If byteorder is 'big', the most significant byte is at the
 67         beginning of the byte array.  If byteorder is 'little', the most
 68         significant byte is at the end of the byte array.  To request the native
 69         byte order of the host system, use `sys.byteorder' as the byte order value.
 70         
 71         The signed keyword-only argument determines whether two's complement is
 72         used to represent the integer.  If signed is False and a negative integer
 73         is given, an OverflowError is raised.
 74         """
 75         pass
 76 
 77     def __abs__(self, *args, **kwargs): # real signature unknown
 78         """ abs(self) """
 79         pass
 80 
 81     def __add__(self, *args, **kwargs): # real signature unknown
 82         """ Return self+value. """
 83         pass
 84 
 85     def __and__(self, *args, **kwargs): # real signature unknown
 86         """ Return self&value. """
 87         pass
 88 
 89     def __bool__(self, *args, **kwargs): # real signature unknown
 90         """ self != 0 """
 91         pass
 92 
 93     def __ceil__(self, *args, **kwargs): # real signature unknown
 94         """ Ceiling of an Integral returns itself. """
 95         pass
 96 
 97     def __divmod__(self, *args, **kwargs): # real signature unknown
 98         #相除,得到商和餘數組成的元組
 99         """ Return divmod(self, value). """
100         pass
101 
102     def __eq__(self, *args, **kwargs): # real signature unknown
103         """ Return self==value. """
104         pass
105 
106     def __float__(self, *args, **kwargs): # real signature unknown
107         """ float(self) """
108         pass
109 
110     def __floordiv__(self, *args, **kwargs): # real signature unknown
111         """ Return self//value. """
112         pass
113 
114     def __floor__(self, *args, **kwargs): # real signature unknown
115         """ Flooring an Integral returns itself. """
116         pass
117 
118     def __format__(self, *args, **kwargs): # real signature unknown
119         pass
120 
121     def __getattribute__(self, *args, **kwargs): # real signature unknown
122         """ Return getattr(self, name). """
123         pass
124 
125     def __getnewargs__(self, *args, **kwargs): # real signature unknown
126         pass
127 
128     def __ge__(self, *args, **kwargs): # real signature unknown
129         """ Return self>=value. """
130         pass
131 
132     def __gt__(self, *args, **kwargs): # real signature unknown
133         """ Return self>value. """
134         pass
135 
136     def __hash__(self, *args, **kwargs): # real signature unknown
137         """ Return hash(self). """
138         pass
139 
140     def __index__(self, *args, **kwargs): # real signature unknown
141         """ Return self converted to an integer, if self is suitable for use as an index into a list. """
142         pass
143 
144     def __init__(self, x, base=10): # known special case of int.__init__
145         #構造方法
146         """
147         int(x=0) -> integer
148         int(x, base=10) -> integer
149         
150         Convert a number or string to an integer, or return 0 if no arguments
151         are given.  If x is a number, return x.__int__().  For floating point
152         numbers, this truncates towards zero.
153         
154         If x is not a number or if base is given, then x must be a string,
155         bytes, or bytearray instance representing an integer literal in the
156         given base.  The literal can be preceded by '+' or '-' and be surrounded
157         by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
158         Base 0 means to interpret the base from the string as an integer literal.
159         >>> int('0b100', base=0)
160         4
161         # (copied from class doc)
162         """
163         pass
164 
165     def __int__(self, *args, **kwargs): # real signature unknown
166         """ int(self) """
167         pass
168 
169     def __invert__(self, *args, **kwargs): # real signature unknown
170         """ ~self """
171         pass
172 
173     def __le__(self, *args, **kwargs): # real signature unknown
174         """ Return self<=value. """
175         pass
176 
177     def __lshift__(self, *args, **kwargs): # real signature unknown
178         """ Return self<<value. """
179         pass
180 
181     def __lt__(self, *args, **kwargs): # real signature unknown
182         """ Return self<value. """
183         pass
184 
185     def __mod__(self, *args, **kwargs): # real signature unknown
186         """ Return self%value. """
187         pass
188 
189     def __mul__(self, *args, **kwargs): # real signature unknown
190         """ Return self*value. """
191         pass
192 
193     def __neg__(self, *args, **kwargs): # real signature unknown
194         """ -self """
195         pass
196 
197     @staticmethod # known case of __new__
198     def __new__(*args, **kwargs): # real signature unknown
199         """ Create and return a new object.  See help(type) for accurate signature. """
200         pass
201 
202     def __ne__(self, *args, **kwargs): # real signature unknown
203         """ Return self!=value. """
204         pass
205 
206     def __or__(self, *args, **kwargs): # real signature unknown
207         """ Return self|value. """
208         pass
209 
210     def __pos__(self, *args, **kwargs): # real signature unknown
211         """ +self """
212         pass
213 
214     def __pow__(self, *args, **kwargs): # real signature unknown
215         """ Return pow(self, value, mod). """
216         pass
217 
218     def __radd__(self, *args, **kwargs): # real signature unknown
219         """ Return value+self. """
220         pass
221 
222     def __rand__(self, *args, **kwargs): # real signature unknown
223         """ Return value&self. """
224         pass
225 
226     def __rdivmod__(self, *args, **kwargs): # real signature unknown
227         """ Return divmod(value, self). """
228         pass
229 
230     def __repr__(self, *args, **kwargs): # real signature unknown
231         #轉化為解釋器可讀取的形式
232         """ Return repr(self). """
233         pass
234 
235     def __rfloordiv__(self, *args, **kwargs): # real signature unknown
236         """ Return value//self. """
237         pass
238 
239     def __rlshift__(self, *args, **kwargs): # real signature unknown
240         """ Return value<<self. """
241         pass
242 
243     def __rmod__(self, *args, **kwargs): # real signature unknown
244         """ Return value%self. """
245         pass
246 
247     def __rmul__(self, *args, **kwargs): # real signature unknown
248         """ Return value*self. """
249         pass
250 
251     def __ror__(self, *args, **kwargs): # real signature unknown
252         """ Return value|self. """
253         pass
254 
255     def __round__(self, *args, **kwargs): # real signature unknown
256         """
257         Rounding an Integral returns itself.
258         Rounding with an ndigits argument also returns an integer.
259         """
260         pass
261 
262     def __rpow__(self, *args, **kwargs): # real signature unknown
263         """ Return pow(value, self, mod). """
264         pass
265 
266     def __rrshift__(self, *args, **kwargs): # real signature unknown
267         """ Return value>>self. """
268         pass
269 
270     def __rshift__(self, *args, **kwargs): # real signature unknown
271         """ Return self>>value. """
272         pass
273 
274     def __rsub__(self, *args, **kwargs): # real signature unknown
275         """ Return value-self. """
276         pass
277 
278     def __rtruediv__(self, *args, **kwargs): # real signature unknown
279         """ Return value/self. """
280         pass
281 
282     def __rxor__(self, *args, **kwargs): # real signature unknown
283         """ Return value^self. """
284         pass
285 
286     def __sizeof__(self, *args, **kwargs): # real signature unknown
287         """ Returns size in memory, in bytes """
288         pass
289 
290     def __str__(self, *args, **kwargs): # real signature unknown
291         """ Return str(self). """
292         pass
293 
294     def __sub__(self, *args, **kwargs): # real signature unknown
295         """ Return self-value. """
296         pass
297 
298     def __truediv__(self, *args, **kwargs): # real signature unknown
299         """ Return self/value. """
300         pass
301 
302     def __trunc__(self, *args, **kwargs): # real signature unknown
303         """ Truncating an Integral returns itself. """
304         pass
305 
306     def __xor__(self, *args, **kwargs): # real signature unknown
307         """ Return self^value. """
308         pass
309 
310     denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
311     """the denominator of a rational number in lowest terms"""
312 
313     imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
314     """the imaginary part of a complex number"""
315 
316     numerator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
317     """the numerator of a rational number in lowest terms"""
318 
319     real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
320     """the real part of a complex number"""    
View Code

幾個常用的功能:

  1. __divmod__():
    1 all_items = 95
    2 pager = 10
    3 result1 = all_items.__divmod__(10)
    4 #__divmod__()功能常用於頁面分頁,如上共95個數據,每頁10個數據。
    5 result2 = all_items.__rdivmod__(10)
    6 print (result1,result2)
    View Code

     

  2. __init__(),構造方法:
    1 >>> n = 19
    2 >>> n = int(19) #這個過程python自動觸發__init__構造方法

     

float內部功能

  1 class float(object):
  2     """
  3     float(x) -> floating point number
  4     
  5     Convert a string or number to a floating point number, if possible.
  6     """
  7     def as_integer_ratio(self): # real signature unknown; restored from __doc__
  8        #獲取浮點數化為分數的最簡比 
  9         """
 10         float.as_integer_ratio() -> (int, int)
 11         
 12         Return a pair of integers, whose ratio is exactly equal to the original
 13         float and with a positive denominator.
 14         Raise OverflowError on infinities and a ValueError on NaNs.
 15         
 16         >>> (10.0).as_integer_ratio()
 17         (10, 1)
 18         >>> (0.0).as_integer_ratio()
 19         (0, 1)
 20         >>> (-.25).as_integer_ratio()
 21         (-1, 4)
 22         """
 23         pass
 24 
 25     def conjugate(self, *args, **kwargs): # real signature unknown
 26         """ Return self, the complex conjugate of any float. """
 27         pass
 28 
 29     def fromhex(self, string): # real signature unknown; restored from __doc__
 30         """
 31         float.fromhex(string) -> float
 32         
 33         Create a floating-point number from a hexadecimal string.
 34         >>> float.fromhex('0x1.ffffp10')
 35         2047.984375
 36         >>> float.fromhex('-0x1p-1074')
 37         -5e-324
 38         """
 39         return 0.0
 40 
 41     def hex(self): # real signature unknown; restored from __doc__
 42         """
 43         float.hex() -> string
 44         
 45         Return a hexadecimal representation of a floating-point number.
 46         >>> (-0.1).hex()
 47         '-0x1.999999999999ap-4'
 48         >>> 3.14159.hex()
 49         '0x1.921f9f01b866ep+1'
 50         """
 51         return ""
 52 
 53     def is_integer(self, *args, **kwargs): # real signature unknown
 54         """ Return True if the float is an integer. """
 55         pass
 56 
 57     def __abs__(self, *args, **kwargs): # real signature unknown
 58         """ abs(self) """
 59         pass
 60 
 61     def __add__(self, *args, **kwargs): # real signature unknown
 62         """ Return self+value. """
 63         pass
 64 
 65     def __bool__(self, *args, **kwargs): # real signature unknown
 66         """ self != 0 """
 67         pass
 68 
 69     def __divmod__(self, *args, **kwargs): # real signature unknown
 70         """ Return divmod(self, value). """
 71         pass
 72 
 73     def __eq__(self, *args, **kwargs): # real signature unknown
 74         """ Return self==value. """
 75         pass
 76 
 77     def __float__(self, *args, **kwargs): # real signature unknown
 78         """ float(self) """
 79         pass
 80 
 81     def __floordiv__(self, *args, **kwargs): # real signature unknown
 82         """ Return self//value. """
 83         pass
 84 
 85     def __format__(self, format_spec): # real signature unknown; restored from __doc__
 86         """
 87         float.__format__(format_spec) -> string
 88         
 89         Formats the float according to format_spec.
 90         """
 91         return ""
 92 
 93     def __getattribute__(self, *args, **kwargs): # real signature unknown
 94         """ Return getattr(self, name). """
 95         pass
 96 
 97     def __getformat__(self, typestr): # real signature unknown; restored from __doc__
 98         """
 99         float.__getformat__(typestr) -> string
100         
101         You probably don't want to use this function.  It exists mainly to be
102         used in Python's test suite.
103         
104         typestr must be 'double' or 'float'.  This function returns whichever of
105         'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the
106         format of floating point numbers used by the C type named by typestr.
107         """
108         return ""
109 
110     def __getnewargs__(self, *args, **kwargs): # real signature unknown
111         pass
112 
113     def __ge__(self, *args, **kwargs): # real signature unknown
114         """ Return self>=value. """
115         pass
116 
117     def __gt__(self, *args, **kwargs): # real signature unknown
118         """ Return self>value. """
119         pass
120 
121     def __hash__(self, *args, **kwargs): # real signature unknown
122         """ Return hash(self). """
123         pass
124 
125     def __init__(self, x): # real signature unknown; restored from __doc__
126         pass
127 
128     def __int__(self, *args, **kwargs): # real signature unknown
129         """ int(self) """
130         pass
131 
132     def __le__(self, *args, **kwargs): # real signature unknown
	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • AOP概述 AOP技術的誕生並不算晚,早在1990年開始,來自Xerox Palo Alto Research Lab(即PARC)的研究人員就對面向對象思想的局限性進行了分析。他們研究出了一種新的編程思想,藉助這一思想或許可以通過減少代碼重覆模塊從而幫助開發人員提高工作效率。隨著研究的逐漸深入,A ...
  • 在離線環境中發佈.NET Core至Windows Server 2008 0x00 寫在開始 之前一篇博客中寫了在離線環境中使用.NET Core,之後一邊學習一邊寫了一些頁面作為測試,現在打算發佈一下試試。看了下官方給出的發佈教程感覺挺詳細的了(https://docs.asp.net/en/l ...
  • QrCodeNet下載地址:http://qrcodenet.codeplex.com/ Controller: View: 效果如下: ...
  • 現階段的項目是採用前後端分離的思想,前端使用的是Angular.JS,後端使用ABP框架,在後端我們通過WebAPI技術來向前端提供json數據。以前是通過MVC來寫前端的代碼,感覺後端有點在控制前端的節奏,一些少量的後端代碼還是需要在HTML頁面中寫的,這次採用的這種模式,前端不需要寫一點後端的C ...
  • 標簽: 依賴註入 Autofac ASPNETCore ASP.NET Core依賴註入解讀&使用Autofac替代實現 1. 前言 2. ASP.NET Core 中的DI方式 3. Autofac實現和自定義實現擴展方法 3.1 安裝Autofac 3.2 創建容器並註冊依賴 4. 參考 ...
  • 定義函數 Python中定義函數的格式為: 函數在執行到return語句時結束,並將結果返回。如果沒有return語句,函數執行完畢後返回None。 例: 結果為: my age is 20 ps :str(x)函數我一開始並不知道具體功能是什麼,只是覺得應該要將int型轉換成string類型再輸出 ...
  • ELF文件格式是一個開發標準,各種UNIX系統的可執行文件都採用ELF格式,它有三種不同的類型: 可重定位的目標文件 可執行文件 共用庫 現在分析一下上一篇文章中經過彙編之後生成的目標文件max.o和鏈接之後生成的可執行文件max的格式,從而理解彙編、鏈接和載入執行的過程。 一、目標文件 ELF文件 ...
  • 一、簡單的彙編程式 以下麵這段簡單的彙編代碼為例 (註意是globl不是global;movl(MOVL)不是mov1(MOV一)) 將這段程式保存為demo.s,然後用彙編器as把彙編程式中的助記符翻譯成機器指令(彙編指令與機器指令是對應的)生成目標文件demo.o。然後用鏈接器ld把目標文件de ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...