python变量分配内存_Python | 声明任何变量而不分配任何值

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变量分配内存

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值