热线电话:13121318867

登录
2019-04-19 阅读量: 2226
python创建一个空类

在python中,想要创建一个空类,可以借助pass函数。

# An empty class
class Test:
pass

#定义实例变量
# Python program to show that we can create
# instance variables inside methods

# Class for Computer Science Student
class CSStudent:

# Class Variable
stream = 'cse'

# The init method or constructor
def __init__(self, roll):

# Instance Variable
self.roll = roll

# Adds an instance variable
def setAddress(self, address):
self.address = address

# Retrieves instance variable
def getAddress(self):
return self.address

# Driver Code
a = CSStudent(101)
a.setAddress("Noida, UP")
print(a.getAddress())
0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子