• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python类属性与实例属性用法分析

Python类属性与实例属性用法分析

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python多线程实例,python数据分析实例,python实例,python程序实例,python脚本实例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例分析了Python类属性与实例属性用法。分享给大家供大家参考。具体如下:

类属性:类名.属性名 

实例属性:实例.属性名

>>> class test():
...  ver=1
... 
>>> a=test()
>>> test.x=8
>>> a.__dict__
{}
>>> a.x
8
>>> a.x=9
>>> a.__dict__
{'x': 9}
</div>

1.类的属性如何模子一样,类属性一旦给出,所有的实例将都取这个值。
2.各个实例的这个属性的值可以变化。
3.某一实例的属性没有显示地给定,a.x可以显示这个属性的值,但是,它没有在名称空间里面。

为了把它加入名称空间,必须显式赋值。

class Instant1(object):
 count=0
 def __init__(self):
  Instant1.count=Instant1.count+1
  print "created instant"
 def howmany(self):
  print Instant1.count
  print self.count

class Instant2(object):
 count=0
 def __init__(self):
  print self.count
  #print Instant2.count
  self.count=self.count+1
  #Instant2.count=Instant2.count+1
  print "created instant"
 def howmany(self):
  print self.count
  print Instant2.count
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python多线程实现同步的四种方式
  • Python多线程实现同步的四种方式
  • Python 多线程实例详解
  • Python 多线程实例详解
  • Python实现的多线程http压力测试代码
  • python实现多线程抓取知乎用户
  • python 线程的暂停, 恢复, 退出详解及实例
  • 深入理解 Python 中的多线程 新手必看
  • python 简单的多线程链接实现代码
  • python 简单的多线程链接实现代码

相关文章

  • Python多线程和队列操作实例
  • Python对列表排序的方法实例分析
  • Python中的exec、eval使用实例
  • Python 26进制计算实现方法
  • Python3遍历目录树实现方法
  • python避免死锁方法实例分析
  • Pyramid Mako模板引入helper对象的步骤方法
  • Python中使用logging模块打印log日志详解
  • 打开电脑上的QQ的python代码
  • python3图片转换二进制存入mysql

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python提取页面内url列表的方法
    • 在Python的Django框架上部署ORM库的教程
    • 详解Python的Django框架中的模版相关知识
    • Python 专题二 条件语句和循环语句的基础知识
    • 在Python中处理字符串之isdecimal()方法的使用
    • 全面了解Python环境配置及项目建立
    • 浅谈Python中的闭包
    • Python实现的金山快盘的签到程序
    • 十条建议帮你提高Python编程效率
    • python中assert用法实例分析

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有