导语:
本文主要介绍了关于python类属性的内存分析的相关知识,包括Python类的属性,以及python 读取内存数据这些编程知识,希望对大家有参考作用。
说明
1、Python在堆内存中创建数据类型为type的student类。
2、student类有类属性classname和teachername两种属性。
3、实例属性不在类中。
而是通过Student(“Tome”、19)创建的对象。
4、实例对象s1.information调用可调用类属性。
实例
class Student:
classname = "Twenty" # 类属性
teachername = "JueJing" # 类属性
count = 0 # 类属性
def __init__(self,name,age): #实例属性
self.name = name
self.age = age
def information(self):
print("{0} ".format(Student.classname)) # 调用类属性
print("{0} age is {1}".format(self.name,self.age)) #调用实例属性
s1 = Student("Tome",19)
s1.information()
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 如何下载安装python3.608/30
- ♥ Python 格式函数字符串格式化入门01/12
- ♥ 如何启动python 3.601/09
- ♥ python中目录结构的介绍和使用10/26
- ♥ Python代码判断水仙花的数量08/15
- ♥ 如何使用python运行文件09/30
内容反馈