当前位置:网站首页>类与对象笔记一
类与对象笔记一
2022-07-26 22:37:00 【久久鸭要变大鹅子】
类
class Dog:
cute = True
def have_it(doggy):
print('eating')
类的实例化
调用语法:实例名 = 类名()
意义:我们有了一个具体的实例,它可以调用所属类的所有属性和方法。
class Dog:
cute = True #这里是属性 狗勾可爱是True
def have_it(doggy): #这里是方法(类里的函数叫方法)
print('eating')
a = Dog() #类的实例化
print(a.cute) #打印类是属性
a.have_it() #调用类的方法
print(a)
创建一个类 —— 类的实例化 —— 用实例调用类的属性和方法。
创建类~~class 类名 :
编写类的属性
编写类里的方法(函数)
类的实例化~ 变量名=类名()
实例名.属性
实例名.方法()
边栏推荐
猜你喜欢
随机推荐
4. Talk about the famous Zhang Zhengyou calibration method
Tensorflow2.0 deep learning simple tutorial of running code
Go exceed API source code reading (IV) -- save (), SaveAs (name string)
分页插件--PageHelper
第1章 开发第一个restful应用
Midge paper reading notes
MVC三层架构
实数范围内的求模(求余)运算:负数求余究竟怎么求
What is Tencent cloud lightweight application server? What are the differences between CVM and ECS?
Design of vision protector based on 51 single chip microcomputer
08_ Event modifier
uni-app学习(二)
Training team lpoj round10 d come minion!
[Gorm] model relationship -hasone
C and pointer Chapter 18 runtime environment 18.7 problems
ResNet论文解读及代码实现(pytorch)
第1章 拦截器入门及使用技巧
Arthas quick start
Complex SQL_ 01
机器学习模型——lightGBM








