亚洲喷奶水中文字幕电影,日本aⅴ高清一区二区三区,欧美亚洲日本国产,欧美日韩亚洲中文字幕

<legend id="flx4p"><abbr id="flx4p"><thead id="flx4p"></thead></abbr></legend>

<mark id="flx4p"><thead id="flx4p"></thead></mark>

      Python面試題目

        1:Python如何實現(xiàn)單例模式?

        Python有兩種方式可以實現(xiàn)單例模式,下面兩個例子使用了不同的方式實現(xiàn)單例模式:

        1.

        class Singleton(type):

        def __init__(cls, name, bases, dict):

        super(Singleton, cls).__init__(name, bases, dict)

        cls.instance = None

        def __call__(cls, *args, **kw):

        if cls.instance is None:

        cls.instance = super(Singleton, cls).__call__(*args, **kw)

        return cls.instance

        class MyClass(object):

        __metaclass__ = Singleton

        print MyClass()

        print MyClass()

        2. 使用decorator來實現(xiàn)單例模式

        def singleton(cls):

        instances = {}

        def getinstance():

        if cls not in instances:

        instances[cls] = cls()

        return instances[cls]

        return getinstance

        @singleton

        class MyClass:

        …

        2:什么是lambda函數(shù)?

        Python允許你定義一種單行的小函數(shù)。定義lambda函數(shù)的形式如下:labmda 參數(shù):表達式lambda函數(shù)默認返回表達式的值。你也可以將其賦值給一個變量。lambda函數(shù)可以接受任意個參數(shù),包括可選參數(shù),但是表達式只有一個:

        >>> g = lambda x, y: x*y

        >>> g(3,4)

        12

        >>> g = lambda x, y=0, z=0: x+y+z

        >>> g(1)

        1

        >>> g(3, 4, 7)

        14

        也能夠直接使用lambda函數(shù),不把它賦值給變量:

        >>> (lambda x,y=0,z=0:x+y+z)(3,5,6)

        14

        如果你的函數(shù)非常簡單,只有一個表達式,不包含命令,可以考慮lambda函數(shù)。否則,你還是定義函數(shù)才對,畢竟函數(shù)沒有這么多限制。

        

      本文已影響6827
      上一篇:linux面試相關問題分享 下一篇:韓國留學簽證面試問題有哪些?

      相關文章推薦

      |||||