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變量分配內存