类名“I”的“不明确的类定义”(Python中的Pep8)

2024-10-03 06:28:42 发布

您现在位置:Python中文网/ 问答频道 /正文

问题: 当我试图定义一个名为I的类时,为什么PEP8会发出警告PEP8: amiguous class definition 'I'?我找不到I中有任何内部版本。在

enter image description here

mwe.py公司:

class I:
    pass

备注:

  • 对于其他单字母名称,例如class E,则不会出现
  • 我无法访问任何其他的内置类、对象或函数I
  • 我在这个问题上的web搜索没有成功,因为“I”远远不是一个唯一的搜索词
  • PyCharm 2019.1.3 (Community Edition)中进行了观察

Tags: 对象py版本名称警告定义字母公司
1条回答
网友
1楼 · 发布于 2024-10-03 06:28:42

根据PEP 8: Names to avoid

Never use the characters 'l' (lowercase letter el), 'O' (uppercase letter oh), or 'I' (uppercase letter eye) as single character variable names.

In some fonts, these characters are indistinguishable from the numerals one and zero. When tempted to use 'l', use 'L' instead.

相关问题 更多 >