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 value
print "value of num: ", num
# checking variable
if (num==None):
print "Nothing"
else:
print "Something"
# assign some value
num = 100
# print the value
print "value of num: ", num
# checking variable
if (num==None):
print "Nothing"
else:
print "Something"
Output
输出量
value of num: None
Nothing
value of num: 100
Something
翻译自: https://www.includehelp.com/python/declare-any-variable-without-assigning-any-value.aspx
python变量分配内存