python 类中静态变量_Python中的类或静态变量

python 类中静态变量

Python类/静态变量 (Python Class / Static Variables)

Class or Static variables are class-related variables that are shared among all objects but the instance or non-static variable is unique for each object. In Python, there is no need for the keyword static to make a class variable but the static keyword is used to make a class or static variables in other programming languages like C++, C, Java, etc. The variable defined on the class level that is declared inside the class but outside any method in Python is static.

类或静态变量是在所有对象之间共享的与类相关的变量,但是实例或非静态变量对于每个对象都是唯一的。 在Python中,不需要使用关键字static来创建类变量,而是使用static关键字来创建类或其他编程语言(例如C ++,C,Java等)中的静态变量。在类级别定义的变量在类内部声明,但在Python中的任何方法外部都是静态的。

Let's look at an example for a better understanding of the static variable that returns some details about the intern of "includehelp" in Python.

让我们看一个示例,以更好地理解静态变量,该变量返回有关Python中“ includehelp”的内部实习生的一些详细信息。

Example for the class or static variable

类或静态变量的示例

# class definition
class intern:
site_name='Includehelp'
field='Technical content writer'
def __init__(self,name,programming_language):
self.name=name
self.programming_language=programming_language
# object of the intern class
x = intern('Bipin Kumar','Python') 
# printing the variables values
print('Site name: ',x.site_name)
print('Field of interest: ',x.field)
print('Name of intern: ',x.name)
print('Language: ',x.programming_language)

Output

输出量

Site name:  Includehelp
Field of interest:  Technical content writer
Name of intern:  Bipin Kumar
Language:  Python

Explanation:

说明:

In the above example, site_name and field is a class or static variable which is declared inside the class "intern" but outside of the __init__ method and name and programming_language are instance variables. Here, x is the object of the class "intern" which has two arguments, one is the name of an intern and another one is the programming language.

在上面的示例中, site_name和field是一个类或静态变量 ,在类“ intern”内声明,但在__init__方法之外,并且name和programming_language是实例变量。 在此, x是“ intern”类的对象,该类具有两个参数,一个是实习生的名称,另一个是编程语言。

翻译自: https://www.includehelp.com/python/class-or-static-variables.aspx

python 类中静态变量

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543951.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

彻底搞懂 SpringBoot 中的 starter 机制

前言我们都知道,Spring的功能非常强大,但也有些弊端。比如:我们需要手动去配置大量的参数,没有默认值,需要我们管理大量的jar包和它们的依赖。为了提升Spring项目的开发效率,简化一些配置,Sprin…

android四大组件之Service 注册广播接收者

广播的注册一共有两种,一种就是用清单文件注册,还有另外一种就是用代码注册,代码注册比较灵活,可以在需要的时候注册,不需要的时候解除注册 用服务注册广播首先要开启服务, 然后在服务oncreate方法里注册广…

c ++向量库_将向量复制到C ++中的另一个向量

c 向量库The ways that we are using to copy vectors in C, are: 我们用于在C 中复制向量的方法是: Copy one vectors elements to another (Simple approach) 将一个向量的元素复制到另一个(简单方法) Copy vector by using an assignment operator 通过使用赋值…

Java 中验证时间格式的 4 种方法

大家好,今天咱们来讲一下,Java 中如何检查一个字符串是否是合法的日期格式?为什么要检查时间格式?后端接口在接收数据的时候,都需要进行检查。检查全部通过后,才能够执行业务逻辑。对于时间格式&#xff0c…

FreeSWITCH的TLS加密

听着很高大上(实际也很实用)的加密机制,在FreeSWITCH里配置支持竟然这么简单! Greate FreeSWITCH and Greate Programmer! ① cd /usr/local/freeswitch/bin(以默认的安装路径为例) ② 产生root…

kotlin 查找id_Kotlin程序查找Sphere的体积

kotlin 查找idFormula to find volume of Sphere: volume (4/3)*PI*r^3 查找球体体积的公式: volume (4/3)* PI * r ^ 3 Given the value of radius, we have to find the volume of Sphere. 给定半径的值,我们必须找到球体的体积。 Example: 例&#…

Redis 实现分布式锁的 7 种方案

前言日常开发中,秒杀下单、抢红包等等业务场景,都需要用到分布式锁。而Redis非常适合作为分布式锁使用。本文将分七个方案展开,跟大家探讨Redis分布式锁的正确使用方式。如果有不正确的地方,欢迎大家指出哈,一起学习一…

css复选框样式_使用CSS样式复选框

css复选框样式Introduction: 介绍: Sometimes we want to develop a website or web page that would contain a form and through that form, we want to get some information from the user. Now that information could be of any type depending on the kind …

大数据计算平台Spark内核全面解读

1、Spark介绍 Spark是起源于美国加州大学伯克利分校AMPLab的大数据计算平台,在2010年开源,目前是Apache软件基金会的顶级项目。随着Spark在大数据计算领域的暂露头角,越来越多的企业开始关注和使用。2014年11月,Spark在Daytona Gr…

javascript对话框_JavaScript中的对话框

javascript对话框JavaScript对话框 (JavaScript Dialog Boxes) Dialog boxes are a great way to provide feedback to the user when they submit a form. In JavaScript, there are three kinds of Dialog boxes, 对话框是向用户提交表单时提供反馈的好方法。 在JavaScript中…

排查死锁的 4 种工具,秀~

作者 | 磊哥来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)死锁(Dead Lock)指的是两个或两个以上的运算单元(进程、线程或协程)&#xf…

MySQL 常见的 9 种优化方法

大家好,我是磊哥!今天给大家分享一些简单好用的数据库优化方式!1、选择最合适的字段属性Mysql是一种关系型数据库,可以很好地支持大数据量的存储,但是一般来说,数据库中的表越小,在它上面执行的…

oracle中dbms_DBMS中的实例和架构

oracle中dbms1)实例 (1) Instances) What is the Instance? If we look towards it in real life, we refer instance as an occurrence of something at a particular moment of time. In Database Management system, there are a lot of changes occurring over time to th…

acess() 判断目录是否存在

acess()功能描述&#xff1a; 检查调用进程是否可以对指定的文件执行某种操作。 <pre lang"c" escaped"true">#include <unistd.h>int access(const char *pathname, int mode); </pre>参数说明&#xff1a;pathname: 需要测试的文件路径…

过滤器和拦截器的 5 个区别!

作者 | 磊哥来源 | Java面试真题解析&#xff08;ID&#xff1a;aimianshi666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;过滤器&#xff08;Filter&#xff09;和拦截器&#xff08;Interceptor&#xff09;都是基于 AOP&#xff08;Aspec…

简单的求和(打表)

简单的求和 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 130 Solved: 20SubmitStatusWeb BoardDescription 定义f(i)代表i的所有因子和(包括1和i)&#xff0c;给定一个l,r。求f(l)f(l1)...f(r)。 Input 第一行输入一个t(t<1000)&#xff0c;代表有t组测试数据&#x…

chroot函数使用_PHP chroot()函数与示例

chroot函数使用PHP chroot()函数 (PHP chroot() function) The full form of chroot is "Change Root", the function chroot()" is used to change the root directory, and, also changes the current working directory to "/". chroot的完整格式为…

面试突击第一季完结:共 91 篇!

感谢各位读者的支持与阅读&#xff0c;面试突击系列第一季到这里就要和大家说再见了。希望所写内容对大家有帮助&#xff0c;也祝你们找到满意的工作。青山不改&#xff0c;细水长流&#xff0c;我们下一季再见&#xff01;91&#xff1a;MD5 加密安全吗&#xff1f;90&#xf…

linux升级python

Centos 6.6自带的是Python 2.6.6, 现在升级为2.7.6[rootoffice-vps4052 ~]# python -VPython 2.6.6操作步骤如下:1) 下载并解压python 2.7.6源码包[rootoffice-vps4052 ~]# cd /usr/local/src[rootoffice-vps4052 ~]# wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tg…

SpringBoot官方热部署和远程调试神器

平时使用SpringBoot开发应用时&#xff0c;修改代码后需要重新启动才能生效。如果你的应用足够大的话&#xff0c;启动可能需要好几分钟。有没有什么办法可以加速启动过程&#xff0c;让我们开发应用代码更高效呢&#xff1f;今天给大家推荐一款SpringBoot官方的热部署工具spri…