Python中has a与is a

可参考链接:is-a和has-a的区别

1、has a 关系

  1. has a :一个类中使用了另外一种自定义的类型
  2. 类型:
    系统类型str、 int、 float、 list 、dict 、 tuple、 set
    自定义类型算是自定义的类,都可以将其当成一种类型。类也可以看成一种类型。

2、is a 关系(继承)

  1. 简单说:就是继承关系。

  2. 如果类中不定义__init__,调用父类 super class的__init__

  3. 如果类继承父类也需要定义自己的__init__,就需要在当前类的__init__调用一下父类__init__

  4. 如何调用父类__init__:

    super().__init__(参数)
    super(类名,对象).__init__(参数)
    
  5. 如果父类有eat()方法,子类也定义了一个eat()方法,默认搜索的原则:先找当前类,再去找父类。父类提供的方法不能满足子类的需求,就需要在子类中定义一个同名的方法,这种行为:重写(override)。

  6. 子类的方法中也可以调用父类方法:super().方法名(参数)。

  7. 示例:

    class Person:
        def __init__(self,name,age):
            self.name = name
            self.age = age
    class Student(Person):
        def __init__(self,name,age,clazz):
            super().__init__(name,age)
            self.clazz = clazz
    
    class Employee(Person):
        def __init__(self,name,age,employer,salary): #报阴影
            # 如何调用父类__init__
            super().__init__(name,age)
            self.employer = employer
            self.salary = salary
    
    class Doctor(Person):
        def __init__(self,name,age):
            super().__init__(name,age)
            self.name = name
            self.age = age
    
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Applications for Python Python is used in many application domains. Here's a sampling. The Python Package Index lists thousands of third party modules for Python. Web and Internet Development Python offers many choices for web development: Frameworks such as Django and Pyramid. Micro-frameworks such as Flask and Bottle. Advanced content management systems such as Plone and django CMS. Python's standard library supports many Internet protocols: HTML and XML JSON E-mail processing. Support for FTP, IMAP, and other Internet protocols. Easy-to-use socket interface. And the Package Index has yet more libraries: Requests, a powerful HTTP client library. BeautifulSoup, an HTML parser that can handle all sorts of oddball HTML. Feedparser for parsing RSS/Atom feeds. Paramiko, implementing the SSH2 protocol. Twisted Python, a framework for asynchronous network programming. Scientific and Numeric Python is widely used in scientific and numeric computing: SciPy is a collection of packages for mathematics, science, and engineering. Pandas is a data analysis and modeling library. IPython is a powerful interactive shell that features easy editing and recording of a work session, and supports visualizations and parallel computing. The Software Carpentry Course teaches basic skills for scientific computing, running bootcamps and providing open-access teaching materials. Education Python is a superb language for teaching programming, both at the introductory level and in more advanced courses. Books such as How to Think Like a Computer Scientist, Python Programming: An Introduction to Computer Science, and Practical Programming. The Education Special Interest Group is a good place to discuss teaching issues. Desktop GUIs The Tk GUI library is included with most binary distributions of Python. Some toolkits that are usable on several platforms are available separately: wxWidgets Kivy, for writing multitouch applications. Qt via pyqt or pyside Platform-specific toolkits are als
The Python programming language reconciles many apparent contradictions: both elegant and pragmatic, both simple and powerful, it’s very high-level yet doesn’t get in your way when you need to fiddle with bits and bytes, and it’s suitable for programming novices as well as great for experts, too. This book is aimed at programmers with some previous exposure to Python, as well as experienced programmers coming to Python for the first time from other languages. The book is a quick reference to Python itself, the most commonly used parts of its vast standard library, and a few of the most popular and useful thirdparty modules and packages, covering a wide range of application areas, including web and network programming, XML handling, database interactions, and highspeed numeric computing. The book focuses on Python’s cross-platform capabilities and covers the basics of extending Python and embedding it in other applications. How This Book Is Organized This book has five parts, as follows. Part I, Getting Started with Python Chapter 1, Introduction to Python Covers the general characteristics of the Python language, its implementations, where to get help and information, how to participate in the Python community, and how to obtain and install Python on your computer(s). Chapter 2, The Python Interpreter Covers the Python interpreter program, its command-line options, and how to use it to run Python programs and in interactive sessions. The chapter mentions text editors for editing Python programs and auxiliary programs for checking your Python sources, along with some full-fledged integrated devel

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值