class parameter(auto storage) and instance parameter(static) in python

Difference between class parameter and instance parameter:

1. instance parameter is static storage, it's only initialized once no matter how many times invoking, and memory address not change during the whole progress  ; It will not be released untill the program exits.  It works in the area of  instances.

2. class parameter is automatic storage, it's released as soon as after called, and will be initialized not only once; it works only in the class area before instance invoked, such as __init__ instance.

In example codes below, the class parameter 'no_inst' is initialized  every time only if  the class is invoked, and value is always set to be 0; but, the instance parameter 'Kls.no_inst' remains in the memory, it is initialized only once, and the value adds by 1 in every invoking.

class parameter and instance parameter
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,491评论 0 23
  • 按照惯例,我应该在开头写一下这座山,解释一些为什么是私人的,又是如何的青。 可是那个谁都会,没什么意思。 昨天下午...
    少女橙梦碎在哪里阅读 1,085评论 0 0
  • 文/洋芋丝丝 “每个灵魂都要找到归宿,每种心情都要有个出口,每样味道都值得被记住。人之所以要靠食物慰藉心灵,无非是...
    洋芋丝丝阅读 4,728评论 39 49
  • 首先感谢‘谈写作’专题举行的活动。你的写作,为名,为利还是为心。 为心?什么鬼?这都第几世纪了?为心? 我想说,我...
    刘阿文阅读 2,713评论 9 4
  • HI~ 不知不觉过了4个多月了,一直忙着工作没时间来简书写东西,露珠跳了槽,离开了生鲜电商到了美业O2O,工作内容...
    AnndyBear阅读 1,495评论 0 1

友情链接更多精彩内容