python learning - reflective practice

1. The difference between class variables and instance variables?

Class variables: the variables defined in the class

Examples of variables: variables defined outside the class

2.super role?

Call the object in order to find the next call functions inherited class

And the difference between 3.isinstance type and by way of example Code Description

Examples isinstance checks the first parameter (object) whether the second parameter (s) of

class Foo(object):

    pass

obj = Foo()

print(obj,isinstance(obj,Foo))

 

Gets the object type is created which class

class Foo(object):

    pass

obj = Foo()

print(obj,type(obj))

if type(obj) == Foo:

  print ( 'obj is Foo')

4. Completion Code

  def func(arg):
    """

    Arg can be called to determine whether, and if so is executed and its return value to print, or to print the results

    param: Incoming parameters

    """

    return 1

  K = func (Arg)

  if callable(arg):

    print(func(arg))

  else:

    print ( 'can not call')   

5. Completion Code

from types import MethodType,FunctionType

def check(*args):
    func_count = 0
    met_count = 0
    foo_count = 0
    for item in args:
        if isinstance(item,MethodType):
            met_count += 1
        elif isinstance(item,FunctionType):
            func_count += 1
        elif type(item) == Foo:
            foo_count += 1
        return met_count,func_count,foo_count
def func():
    pass

class Foo(object):
    def detail(self):
        pass
    @staticmethod
    def xxx():
        pass
obj = Foo()
print(check(func,obj.detail,obj.xxx))

 

6.  

 

Guess you like

Origin www.cnblogs.com/bilx/p/11391937.html