如何在Python中声明没有值的属性?

在Python以及其他几种语言中,有一个值表示“无值”。在Python中,没有值的值为None。所以下面显示了如何使用None-

class Student:
   StudentName = None
   RollNumber = None

这些就像实例变量,而不是类变量,因此我们也可以这样写:

class Student(object):
    def __init__(self):
        self.StudentName = None
        self.RollNumber = None

我们可以在下面的代码中看到Python如何隐式分配None值-

def h():
    pass
k = h() # k now has the value of None