日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python公共变量_Python中的公共变量

發(fā)布時間:2025/3/11 python 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python公共变量_Python中的公共变量 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

python公共變量

By default all numbers, methods, variables of the class are public in the Python programming language; we can access them outside of the class using the object name.

默認(rèn)情況下,該類的所有數(shù)字,方法和變量在Python編程語言中都是公共的。 我們可以使用對象名稱在類外部訪問它們。

Consider the given example:

考慮給定的示例:

Here, we have two variables name and age both are initializing with default values ("XYZ" and 0) while declaring the object using __init__ method.

在這里,我們有兩個變量name和age都使用默認(rèn)值( “ XYZ”和0 )初始化,同時使用__init__方法聲明對象。

Later, in the program, outside of the class definition – we are assigning some values ("Amit" and 21) to name and age, that is possible only if variables are public.

后來,在程序中,在類定義之外–我們?yōu)閚ame和age分配了一些值( “ Amit”和21 ),只有在變量為public的情況下才可能。

Example:

例:

# Python example for public variables class person:def __init__(self):# default valuesself.name = "XYZ"self.age = 0def printValues(self):print "Name: ",self.name print "Age : ",self.age# Main code # declare object p = person() # print p.printValues();# since variables are public by default # we can access them directly here p.name = "Amit" p.age = 21 # print p.printValues ();

Output

輸出量

Name: XYZ Age : 0 Name: Amit Age : 21

翻譯自: https://www.includehelp.com/python/public-variables.aspx

python公共變量

總結(jié)

以上是生活随笔為你收集整理的python公共变量_Python中的公共变量的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。