有谁知道为什么python允许你在一个对象和被称为"."的方法的名称之间放置无限量的空格.?
这里有些例子:
>>> x = []
>>> x. insert(0, 'hi')
>>> print x
['hi']
Run Code Online (Sandbox Code Playgroud)
另一个例子:
>>> d = {}
>>> d ['hi'] = 'there'
>>> print d
{'hi': 'there'}
Run Code Online (Sandbox Code Playgroud)
课程也是如此.
>>> myClass = type('hi', (), {'there': 'hello'})
>>> myClass. there
'hello'
Run Code Online (Sandbox Code Playgroud)
我正在使用python 2.7我尝试做一些谷歌搜索并查看python源代码,但我找不到任何理由为什么这是允许的.