如何在python中调用类函数

时间:2017-10-19 15:33:16

标签: python

class TwoCard:
  def __init__(self, card1, card2):
     self.card1 = card1
     self.card2 = card2

如何拨打card1或2

1 个答案:

答案 0 :(得分:2)

class TwoCard:
  def __init__(self, card1, card2):
     self.card1 = card1
     self.card2 = card2

def f():
    print('f called')
def g():
    print('g called')

two = TwoCard(f, g)

two.card1()    # call card1
two.card2()    # call card2

输出:

f called
g called