导语:
本文主要介绍了关于python中的class是什么的相关知识,包括python中class的定义及使用,以及class是python标识符吗这些编程知识,希望对大家有参考作用。
1、概念
用于描述具有相同属性和方法的对象的集合。它定义了集合中每个对象共有的属性和方法。
2、类定义的语法
class ClassName:
<statement-1>
.
.
.
<statement-N>
3、实例
为了代码的编写方便简洁,引入了类的定义;
一般情况下,使用class语句创建一个新类,后跟类名(通常大写)并以冒号结尾,例如: ,
class Ticket():
def __init__(self,checi,fstation,tstation,fdate,ftime,ttime):
self.checi=checi
self.fstation=fstation
self.tstation=tstation
self.fdate=fdate
self.ftime=ftime
self.ttime=ttime
def printinfo(self):
print("车次:",self.checi)
print("出发站:", self.fstation)
print("到达站:", self.tstation)
print("出发时间:", self.fdate)
以上就是python中class的介绍,在面向对象中我们会频繁接触到这个概念,本篇先把class的基本内容学会吧。
更多Python学习推荐:
(推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 如何查看python工具包12/21
- ♥ 如何在python中定义一个不定长的二维数组?10/06
- ♥ python中repr函数的作用是什么?10/25
- ♥ python3 os输出文件路径的方法有哪些?01/05
- ♥ python中Sobel算子的使用方法12/25
- ♥ Python实用xlwt单元格添加超链接09/08
内容反馈