本文共 1110 字,大约阅读时间需要 3 分钟。
python变量分配内存
Since, Python is a dynamic programming language so there is no need to declare such type of variable, it automatically declares when first time value assign in it.
由于Python是一种动态编程语言,因此无需声明此类变量,它会在首次分配值时自动声明。
Still, this is a common question asked by many programmers that can we declare any variable without any value?
尽管如此,这是许多程序员提出的一个常见问题, 我们可以声明没有任何值的任何变量吗?
The answer is: "Yes! We can declare such type of variable". To declare a variable without any variable, just assign None.
答案是:“是!我们可以声明这种类型的变量” 。 要声明不带任何变量的变量,只需分配None即可 。
Syntax:
句法:
variable_name = None
Example:
例:
num = None
Let’s understand through a program:
让我们通过一个程序来理解:
# Python program to declare a # variable without assigning any value # declare variable num = None# print the valueprint "value of num: ", num# checking variableif (num==None): print "Nothing"else: print "Something" # assign some valuenum = 100# print the valueprint "value of num: ", num# checking variableif (num==None): print "Nothing"else: print "Something"
Output
输出量
value of num: None Nothing value of num: 100 Something
翻译自:
python变量分配内存
转载地址:http://nfazd.baihongyu.com/