Python-47-物件導向12.類別函數(方法)裡面帶參數

類別函數(方法)裡面帶參數

類別函數(方法)裡面帶參數

 

class cyl_ticket2:
  def __init__(myparam,order,fund,people):
     myparam.order = order 
     myparam.fund = fund
     myparam.people = people

  def info(aaa,param1): #(參數1=類別參數固定的,自訂參數1,自訂參數n)
      print("訂購人:"+aaa.order+"共買了"+str(aaa.people)+"張門票共"+str(aaa.fund*aaa.people)+"元"+param1)
   
data3 = cyl_ticket2("yiru",100,8)
data3.info("123")
print(data3.fund)

data4 = cyl_ticket2("ruyi",200,7)
data4.info("456")
print(data4.order)

看看效果

 

Yiru@Studio - 關於我 - 意如