Python object creation

后端 未结 3 1189
暗喜
暗喜 2020-12-11 05:50

I am pretty new to Python world and trying to learn it.

This is what I am trying to achieve: I want to create a Car class, its constructor checks for the input to se

3条回答
  •  长情又很酷
    2020-12-11 06:05

    You don't define a variable, and you use init and self. Like this:

    class Car(Object):
        def __init__(self,input):
            self.carName = input
    
        def showName(self):
            print self.carName
    
    a = Car("bmw")
    a.showName()
    

提交回复
热议问题