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 class
class sample:
pass
# printing its type
print("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=id
self.__name = name
self.__course = course
# function to get/print data
def showData(self):
print("Id\t:",self.__id)
print("Name\t:", self.__name)
print("Course\t:", self.__course)
# main function definition
def main():
#Student class Object
std=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关键字相关推荐
- python 示例_Python中带有示例的关键字除外
python 示例 Python关键字除外 (Python except keyword) except is a keyword (case-sensitive) in python, it is ...
- c++ cdi+示例_C ++中带有示例的本地类
c++ cdi+示例 C ++中的本地类 (Local Class in C++) In C++, generally a class is declared outside of the main( ...
- np.cosh没有分配_Python中带有示例的math.cosh()方法
np.cosh没有分配 Python math.cosh()方法 (Python math.cosh() method) math.cosh() method is a library method ...
- math.ceil带小数点_Python中带有示例的math.ceil()方法
math.ceil带小数点 Python math.ceil()方法 (Python math.ceil() method) math.ceil() method is a library metho ...
- c语言 函数的参数传递示例_C ++中带有示例的nearint()函数
c语言 函数的参数传递示例 C ++附近的int()函数 (C++ nearbyint() function) nearbyint() function is a library function o ...
- python参数化_Python 中如何实现参数化测试的方法示例
之前,我曾转过一个单元测试框架系列的文章,里面介绍了 unittest.nose/nose2 与 pytest 这三个最受人欢迎的 Python 测试框架. 本文想针对测试中一种很常见的测试场景,即参 ...
- python sep函数_Python中带有print()函数的sep参数
python sep函数 sep parameter stands for separator, it uses with the print() function to specify the se ...
- ruby hash方法_Ruby中带有示例的Hash.rehash方法
ruby hash方法 Hash.rehash方法 (Hash.rehash Method) In this article, we will study about Hash.rehash Meth ...
- kafka python框架_Python中如何使用Apache Avro——Apache的数据序列化系统
了解如何创建和使用基于Apache Avro的数据,以实现更好,更有效的传输. 在这篇文章中,我将讨论Apache Avro,这是一种开源数据序列化系统,Spark,Kafka等工具正在使用该工具进行 ...
最新文章
- request.getParameter()与request.setAttribute()的区别
- HTML a 标签的正则表达式
- 介绍ASP.NET控件ID
- GCDAynscSocket简单使用-客户端
- java replace三个参数_javascript replace()第二个参数为函数时的参数用法
- QCC3x系列蓝牙芯片
- 影视剪辑,视频剪辑的万能剪辑技巧来啦,剪辑技巧合集
- python发邮件给多个人发送消息_python发送邮件(带附件)、发送给多人、抄送给多人的示例...
- windows系统oracle11.2.0.4打补丁
- IPSec IKEv1IKEv2
- 下列内容属于计算机房控制功能的是,前厅服务员中级理论知识试卷及答案2
- 2022南理工824专考研经验
- numpy提取某行(列)或某几行(列)
- 【C/C++高质量代码】-----第二章 命名规则
- Intellij idea Ultimate版本学生免费注册使用步骤以及Github学生包
- 2022亚太杯C题思路代码分析
- unity_Text文本和图片组合
- 饱和非线性、非饱和非线性
- collapse 微信小程序_详解优化你的微信小程序
- 源码编译freeswitch-1.10.7遇到问题总结
热门文章
- 局域网内文件传输速度_详解蒲公英路由器组网 实现文件共享
- php-fpm初始化失败,FPM的初始化 - [ PHP7的内核剖析 ] - 在线原生手册 - php中文网
- java 设计模式原则_Java设计模式的七大原则
- RPC 服务 与 HTTP 服务的区别
- JDK源码解析之 Java.lang.String
- 浏览器拦截跨域请求处理方法(已阻止跨源请求:同源策略禁止读取远程资源)
- Hadoop生态圈-Ambari控制台功能简介
- ng-notadd 0.10.1,基于 Angular7 和 material2 的中后台解决方案
- 6.6(java学习笔记)文件分割(IO综合例子)
- java.util (Collection接口和Map接口)