【发布时间】:2018-01-23 22:58:00
【问题描述】:
我真的很喜欢遵循标准的编码风格,但找不到答案。
class Card:
"""Card class representing a playing card."""
RANKS = (None, 'Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10',
'Jack', 'Queen', 'King')
SUITS = ('Clubs', 'Spades', 'Diamonds', 'Hearts')
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
def __str__(self):
return f"{Card.RANKS[self.rank]} of {Card.SUITS[self.suit]}"
c = Card(1, 1)
print(c)
我应该在类属性 all_lower_case 还是 ALL_UPPER_CASE 中写常量? PEP8 只是说常量应该是模块级别的 ALL_UPPER_CASE。上课呢?
【问题讨论】:
标签: python class constants python-3.6 pep8