新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中的class是什么
1、概念

用來描述具有相同的屬性和方法的對象的集合。它定義了該集合中每個對象所共有的屬性和方法。
2、類定義的語法
class ClassName:. . .
3、實例
為了代碼的編寫方便簡潔,引入了類的定義;
一般,使用 class 語句來創(chuàng)建一個新類,class之后為類的名稱(通常首字母大寫)并以冒號結(jié)尾,例如:、
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("出發(fā)站:", self.fstation)
print("到達站:", self.tstation)
print("出發(fā)時間:", self.fdate)
以上就是python中class的介紹,在面向?qū)ο笾形覀儠l繁接觸到這個概念,本篇先把class的基本內(nèi)容學(xué)會吧。更多Python學(xué)習(xí)推薦:python教學(xué)
(推薦操作系統(tǒng):windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。)
當前標題:創(chuàng)新互聯(lián)Python教程:python中的class是什么
文章網(wǎng)址:http://www.fisionsoft.com.cn/article/dpcjces.html


咨詢
建站咨詢
