当前位置:网站首页>实例041:类的方法与变量
实例041:类的方法与变量
2022-08-04 01:35:00 【懒笑翻】
题目:模仿静态变量的用法。
程序分析:构造类,了解类的方法与变量。
代码:
def dummy():
i = 0
print(i)
i += 1
class cls:
i = 0
def dummy(self):
print(self.i)
self.i += 1
a = cls()
for i in range(50):
dummy() # 建议这两个方法分别调用看运行效果
a.dummy()
效果:
我们发现dummy()函数的调用输出结果全部是0
我们又发现cls()类中的dummy()方法中i+=1是有效的
"""
学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群,扫码下方官方推荐的群即可进入哦
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!↓↓↓↓↓↓
"""
边栏推荐
- html select标签赋值数据库查询结果
- C 学生管理系统_分析
- C 学生管理系统 显示链表信息、删除链表
- Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
- 持续投入商品研发,叮咚买菜赢在了供应链投入上
- appium软件自动化测试框架
- 可变字符串
- Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg
- splice随机添加和删除的写法
- typescript50 - type specification between cross types and interfaces
猜你喜欢
Electronics manufacturing enterprise deployment WMS what are the benefits of warehouse management system
Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg
TensoFlow学习记录(二):基础操作
pygame 中的transform模块
- heavy OpenCV 】 【 mapping
哎,又跟HR在小群吵了一架!
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
ASP.NET 获取数据库的数据并写入到excel表格中
typescript55-泛型约束
随机推荐
114. How to find the cause of Fiori Launchpad routing error by single-step debugging
typescript48 - type compatibility between functions
Thinkphp commonly used techniques
ASP.NET 获取数据库的数据并写入到excel表格中
计算首屏时间
typescript55 - generic constraints
MySQL回表指的是什么
typescript48-函数之间的类型兼容性
Promise solves blocking synchronization and turns asynchronous into synchronous
LeetCode third topic (the Longest Substring Without Repeating Characters) trilogy # 3: two optimization
Observability:你所需要知道的关于 Syslog 的一些知识
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
【虚拟化生态平台】虚拟化平台esxi挂载USB硬盘
jmeter distributed stress test
螺旋矩阵_数组 | leecode刷题笔记
Apache DolphinScheduler actual combat task scheduling platform - a new generation of distributed workflow
redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)
.NET Static Code Weaving - Rougamo Release 1.1.0
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
nodejs安装及环境配置