学习笔记(05):21天通关Python(仅视频课)-定义类

立即学习:https://edu.csdn.net/course/play/24797/282185?utm_source=blogtoedu

为什么 输出结果有【None】呢????

import random


class testA:
    print("testA 类")


class testB:
    fstr = 'test%s' % 'B 类'
    print(fstr)


class testC:
    print('testC 类')

    def testCfun(self):
        self.name = 'testC'
        self.age = random.randint(0, 10)
        return print('名字:%s,年龄:%s' % (self.name, self.age))

    def testCfun2(self):
        print('返回随机数%s' % random.randint(0, 10))


testA.name = "testAAA"
testB.name = 'testBBB'

del testB.name

print(testA.name)
print(testB.fstr)
print(testC().testCfun())
print(testC().testCfun2())
# print(testB.name)

输出结果:

testA 类
testB 类
testC 类
testAAA
testB 类
名字:testC,年龄:3
None
返回随机数0
None
 

发布了25 篇原创文章 · 获赞 4 · 访问量 611

猜你喜欢

转载自blog.csdn.net/happyk213/article/details/105135407
今日推荐