Python  class 2

5.initializing a class
define the init()function of the Car class to take four inputs:self,model,color,and mpg.
Assign the last three inputs to member variables of the same name by using the self keyword.
Then,modify the object my_car to provide the following inputs at initialization:
model = "DeLorean"
color = "silver"
mpg = 88
you don't need to include the self keyword when you create an instance of a class ,because self gets added to the beginning of your list of inputs automatically by the class definition.

class Car(object):
condition ="new"
def init(self,model,color,mpg):
self.model = model
self.color = color
self.mpg = mpg
my_car =Car("DeLorean","silver",88)

def 要缩格,不能顶头写,不然程序会出错

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 今日别人的重阳 他日自己的节目 时间的脚步不会停 别人的故事还继续 要不是飙哥的红包 要不是媳妇的提醒 父母所为 ...
    一度一阅读 209评论 0 0
  • (五律平水韵) 春浓新草碧。燕雀复环帏 作树连根紧,为禽比翼飞 晨梳忧脸瘦,夜寝苦衣肥。 最恨天涯远...
    梁红兵阅读 341评论 2 7
  • 春节这段时间,有两个人,让我产生了写这篇文章的想法。 先讲讲我今天拜访的一位客户,这是在一家做国际教育的培训机构里...
    周周赋能阅读 902评论 0 3
  • 做一个好的写作者,是成为一个好的远程工作者的必要条件。由于在远程,大部分的交流和工作都是通过邮件、即时通讯或聊天室...
    梅晨斐阅读 1,790评论 4 15