品易云推流 关闭
文章详情页
文章 > Python基础教程 > python类属性的内存分析

python类属性的内存分析

python类属性 内存

头像

小妮浅浅

2021-08-20 09:11:063323浏览 · 0收藏 · 0评论

说明

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()

以上就是python类属性的内存分析,希望对大家有所帮助。更多Python学习指路:python基础教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图