If the convention in Python is to capitalize classes, why then is list() not capitalized? Is it not a class?

前端 未结 5 1475
耶瑟儿~
耶瑟儿~ 2020-12-08 15:17

Often when I see class definitions class Foo:, I always see them start with upper case letters.

However, isn\'t a list [] or a dict {

5条回答
  •  醉梦人生
    2020-12-08 15:59

    Yes, uppercase-initial classes are the convention, as outlined in PEP 8.

    You are correct that many builtin types do not follow this convention. These are holdovers from earlier stages of Python when there was a much bigger difference between user-defined classes and builtin types. However, it still seems that builtin or extension types written in C are more likely to have lowercase names (e.g., numpy.array, not numpy.Array).

    Nonetheless, the convention is to use uppercase-initial for your own classes in Python code.

提交回复
热议问题