1 Star 0 Fork 0

roohom/OOP

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
OOP06.py 974 Bytes
一键复制 编辑 原始数据 按行查看 历史
unknown 提交于 2018-10-18 21:53 . Initial commit
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File : OOP06.py
# Author: roohom
# Date : 2018/10/18 0018
# 子类与父类之间的关系
class Person(object):
sex = "male"
def __init__(self, age, name):
self.age = age
self.name = name
print("__init__(self) of Person")
def Hello(self, friend):
print("Hello,", friend)
class Student(Person):
def __init__(self, num):
self.number = num
def fun(self):
print(self.sex, self.name, self.number, self.age)
class Worker(Person):
def __init__(self, company, age, name):
self.company = company
super(Worker, self).__init__(age, name)
def fun(self):
print(self.sex, self.name, self.company, self.age)
student1 = Student("20181018")
student1.name = "roohom"
student1.age = 21
student1.fun()
student1.Hello("Python")
worker = Worker("Xiaomi", 21, "LittleBAI")
worker.sex = "Female"
worker.fun()
worker.Hello("LittleRED")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/roohom/OOP.git
git@gitee.com:roohom/OOP.git
roohom
OOP
OOP
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385