Python面向对象基础详解编程语言
2023-06-13 09:11:50 时间
print("Person.__doc__:" , Person.__doc__)#类的文档字符串
print("Person._name_:", Person.__name__)#类名
print("Person.__module__:",Person.__module__)#类定义所在的模块(类的全名是__main__.className,如果类位于一个导入模块mymod中,那么className.__module__ 等于 mymod)
print("Person.__bases__", Person.__bases__)#类的所有父类构成元素(包含了一个由所有父类组成的元组)
print("Person.__dict__:", Person.__dict__)# 类的属性(包含一个字典,由类的数据属性组成)
emp1=Person("Zara","female",18)
emp2=Person("Mi","male",18)
emp1.displayEmployee()
/Users/xxx/PycharmProjects/xxx/venv/bin/python /Users/xxx/PycharmProjects/xxx/ceshi.py Person.__doc__: 人的基类 Person._name_: Person Person.__module__: __main__ Person.__bases__ ( class object ,) Person.__dict__: {__module__: __main__, __doc__: 人的基类, perCount: 0, __init__: function Person.__init__ at 0x108bcce18 , displayCount: function Person.displayCount at 0x108bccd08 , displayEmployee: function Person.displayEmployee at 0x108bccea0 , __dict__: attribute __dict__ of Person objects , __weakref__: attribute __weakref__ of Person objects } Name: Zara , age: 18 Process finished with exit code 0
self表示类的实例,非类本身。
2. inherit
class Person: 人的基类 def __init__(self, name, gender, age): self.name=name self.gender=gender self.age=age def modifyAttri(self,attri): self.attri=attri print("Attri: ",self.attri) class Female(Person): 女性类 def __init__(self,hobby): self.hobby=hobby print("hobby: ",self.hobby) def getFamilyInfo(self): print("Ten members in hers family.") c=Female("swimming")#实例化一个对象 c.getFamilyInfo()#调用子类方法 c.modifyAttri("SWIMING")#调用父类方法
hobby: swimming Ten members in hers family. Attri: SWIMING Process finished with exit code 0
下面看下子类调用父类构造方法:
3. override
18726.html
cjavapython相关文章
- Python-基础04-数据类型
- Python获取时间戳_python爬虫时间戳
- Python基础知识点整理之基本语法元素[通俗易懂]
- Python学习总结之基础语法知识汇总(一)
- 【说站】python温度转换代码
- Python 反转字符串_python输出字符串
- python抛出异常和捕获异常_Python异常
- Python基础:标准库和常用的第三方库「建议收藏」
- Python绘制旭日图_python绘制散点图
- python deepcopy函数_Python deepcopy
- Python基础-12 虚拟环境和包
- 软件测试|Python基础之面向对象(二)
- Python基础语法-基本数据类型-布尔值
- Python 语法基础
- Python基础语法-函数-迭代器生成斐波那契数列
- Python基础语法-函数-递归函数计算斐波那契数列
- Python基础语法-内置函数和模块-常用内置函数(一)
- Python基础之第三篇详解编程语言
- Python基础学习笔记详解编程语言
- python全栈开发-Day8 函数基础详解编程语言
- Python学习:3.Python学习基础详解编程语言
- Python基础(二):列表和元组详解编程语言
- python基础详解编程语言
- Python 基于python实现的http+json协议接口自动化测试框架源码(实用改进版)详解编程语言
- python-阶乘详解编程语言
- Python输出函数print()总结(python print())详解编程语言
- Python面试基础题-2018-12-26详解编程语言
- python的memory_profiler模块使用详解编程语言
- Python如何使用MySQL构建立连接(python怎么连接mysql)
- Linux系统下安装Python模块指南(linux安装python模块)