__builtins__ 周围的引号?

quotes around __builtins__?

(Python 3.6, IDLE) 如果我在 shell 中键入 dir(__builtins__),我会得到一长串异常和函数,从 'ArithmeticError' 到 'zip.' 但是 dir('__builtins__') 产生了不同的对象、属性和函数列表,其中许多似乎是字符串函数。 dir('__builtins__') 正在访问什么?

事物周围的引号是 Python 中的字符串文字。字符串只是另一种类型的对象,确切地说是 str 类型。当给出参数时,dir returns:

an alphabetized list of names comprising (some of) the attributes of the given object

您向它传递了一个 str 对象,因此它包含字符串方法名称,例如 'islower', 'isnumeric', 'isprintable', 'isspace' 等...

您可以将任何其他 str 对象传递给它,您会得到相同的结果,请尝试:

dir('foo')