1 Star 0 Fork 0

roohom/OOP

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
OOP04.py 992 Bytes
一键复制 编辑 原始数据 按行查看 历史
unknown 提交于 2018-10-18 21:53 . Initial commit
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File : OOP04.py
# Author: roohom
# Date : 2018/10/17 0017
# 构造函数
class Student(object):
def __init__(self, first ="", last ="", id=0):
self.firstnamestr = first
self.lasnamestr = last
self.idint = id
a = Student()
print(a.firstnamestr)
b = Student(first="HELLO", last="Python")
print(b.firstnamestr, b.lasnamestr)
print("=" * 30)
# 析构函数
class Car:
def __init__(self, n):
self.num = n
print("编号为", self.num, "的对象born了!")
def __del__(self):
print("编号为", self.num, "的对象dead了!")
car1 = Car(1)
car2 = Car(2)
del car1
del car2
class InstCt(object):
count = 0
def __init__(self):
InstCt.count += 1
def __del__(self):
InstCt.count -= 1
def howMany(self):
return InstCt.count
a = InstCt()
b = InstCt()
print(b.howMany())
print(a.howMany())
del b
print(a.howMany())
del a
print(InstCt.count)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/roohom/OOP.git
git@gitee.com:roohom/OOP.git
roohom
OOP
OOP
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385