久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

pythonClass:面向?qū)ο蟾呒壘幊蘝_getitem__

官網(wǎng)解釋:

創(chuàng)新互聯(lián)建站專注于企業(yè)成都營銷網(wǎng)站建設、網(wǎng)站重做改版、富蘊網(wǎng)站定制設計、自適應品牌網(wǎng)站建設、H5高端網(wǎng)站建設商城網(wǎng)站建設、集團公司官網(wǎng)建設、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應式網(wǎng)頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為富蘊等各大城市提供網(wǎng)站開發(fā)制作服務。

  • object.__getitem__(selfkey)

  • Called to implement evaluation of self[key]. For sequence types,the accepted keys should beintegersandslice objects. Note that the special interpretation of negative indexes (if the class wishes to emulate a sequence type) is up to the __getitem__()method. If key is of an inappropriate type, TypeError may be raised; if of a value outside the set of indexes for the sequence (after any special interpretation of negative values), IndexError should be raised. For mapping types, if key is missing (not in the container), KeyError should be raised.

    Note:

    for loops expect that an IndexError will be raised for illegal indexes to allow proper detection of the end of the sequence.

對于Fibonacci數(shù)列,當我們想抽取特定位置的值看,那又該怎么做,于是就出來了__getitem__這樣的函數(shù)。

int、list類型:切片(沒有step)

#!/usr/bin/python

# -*- coding: utf-8 -*-

class Fib(object):

    def __getitem__(self, n):

        if isinstance(n, int): # n是索引

            a, b = 1, 1

            for x in range(n):

                a, b = b, a + b

            return a

        if isinstance(n, slice): # n是切片

            start = n.start

            stop = n.stop

            if start is None:

                start = 0

            a, b = 1, 1

            L = []

            for x in range(stop):

                if x >= start:

                    L.append(a)

                a, b = b, a + b

            return L

            

f = Fib()

print f[0:4]

python Class:面向?qū)ο蟾呒壘幊?__getitem__

print f[9]

python Class:面向?qū)ο蟾呒壘幊?__getitem__

新聞標題:pythonClass:面向?qū)ο蟾呒壘幊蘝_getitem__
網(wǎng)址分享:http://sd-ha.com/article30/jsjdso.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供面包屑導航、網(wǎng)站收錄、網(wǎng)站營銷、外貿(mào)建站品牌網(wǎng)站制作、

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設