日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python 示例_Python中带有示例的class关键字

發布時間:2025/3/11 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 示例_Python中带有示例的class关键字 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

python 示例

Python類關鍵字 (Python class keyword)

class is a keyword (case-sensitive) in python, it is used to define a class, when we need to define a class, before the class name - we must have to use class keyword.

class是python中的一個關鍵字(區分大小寫),用于定義一個類,當我們需要定義一個類時,在類名之前-我們必須使用class keyword 。

Syntax of class keyword

類關鍵字的語法

class class_name:class definition statements;

Example:

例:

Input:# an empty classclass sample:pass# printing its typeprint("type of class: ", type(sample))Output:type of class: <class 'type'>

類關鍵字的Python示例 (Python examples of class keyword)

Example 1: Define an empty class using pass statement and print its type

示例1:使用pass語句定義一個空類并打印其類型

# python code to demonstrate example of # class keyword # an empty class class sample:pass# main code # printing it's type print("type of class: ", type(sample))

Output

輸出量

type of class: <class 'type'>

Example 2: Define a class student and assign values and print

示例2:定義班級學生并分配值并打印

# python code to demonstrate example of # class keyword # student class code in Python# class definition class Student:__id=0__name=""__course=""# function to set data def setData(self,id,name,course):self.__id=idself.__name = nameself.__course = course# function to get/print datadef showData(self):print("Id\t:",self.__id)print("Name\t:", self.__name)print("Course\t:", self.__course)# main function definition def main():#Student class Objectstd=Student()std.setData(1,'Manju','M. Com.')std.showData()if __name__=="__main__":main()

Output

輸出量

Id : 1 Name : Manju Course : M. Com.

翻譯自: https://www.includehelp.com/python/class-keyword-with-example.aspx

python 示例

總結

以上是生活随笔為你收集整理的python 示例_Python中带有示例的class关键字的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。