Python基础知识学习 Day7

霸气de小男生 提交于 2020-01-21 00:41:07

一、零碎知识点

1、面向对象示例

import datetime

class Book:
    def __init__(self,
                 title,
                 price=0.0,
                 author='',
                 publisher=None,
                 pubdate=datetime.date.today()):
        self.title = title
        self.price = price
        self.author = author
        self.publisher = publisher
        self.pubdate = pubdate
    
    def __repr__(self):
        return '<图书> {} at {}'.formate(self.title,id(self))
    
    def print_info(self):
        print('当前这本书的信息如下:')
        print('标题:{}'.format(self.title))
        print('定价:{}'.format(self.price))
        print('作者:{}'.format(self.author))
        print('出版社:{}'.format(self.publisher))
        print('出版日期:{}'.format(self.pubdate))


book1 = Book('c精典',29.9,'Tom','优品课堂',datetime.date(2016,3,1))
book1.print_info()
print()
book2 = Book('Flask 入门到精通')
book2.print_info()

结果如下:

当前这本书的信息如下:
标题:c精典
定价:29.9
作者:Tom
出版社:优品课堂
出版日期:2016-03-01

当前这本书的信息如下:
标题:Flask 入门到精通
定价:0.0
作者:
出版社:None
出版日期:2020-01-20

二、Xmind

在这里插入图片描述

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!