为什么在Python中'声明'变量?

hen*_*tha 1 python variable-declaration

我之前在Google上搜索了一些与Python相关的问题,并偶然发现了这个页面.作者做了类似以下的事情:

class TestClass(object):
    first = str()
    def __init__(self):
        self.first = "Hello"
Run Code Online (Sandbox Code Playgroud)

那个"声明"这个变量first有什么意义呢?我以前从未见过这样做过,而且我不能为我的生活想到这样一种情况,即在为变量赋值之前创建一个变量是有益的.

上面的例子可能看起来像这样:

class TestClass(object):
    def __init__(self, first="Hello"):
        self.first = first
Run Code Online (Sandbox Code Playgroud)

......或者我错过了什么?

jam*_*lak 6

作者使用的事实

first = str()
Run Code Online (Sandbox Code Playgroud)

而不是

first = ''
Run Code Online (Sandbox Code Playgroud)

表演,一起设置self.first__init__无论如何,有就是没有这样做,目的.

也许作者很困惑并且认为python变量需要首先声明 -_-(在查看链接时很明显)