2 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
隨著學(xué)習(xí)的深入,用不了多久,你就可以寫復(fù)雜的上千甚至上萬(wàn)行的代碼啦,有些代碼你花了很久寫出來(lái),過(guò)了些天再回去看,發(fā)現(xiàn)竟然看不懂了,哈哈,這太正常了。 另外,你以后在工作中會(huì)發(fā)現(xiàn),一個(gè)項(xiàng)目多是由幾個(gè)甚至幾十個(gè)開發(fā)人員一起做,你要調(diào)用別人寫的代碼,別人也要用你的,如果代碼不加注釋,你自己都看不懂,更別說(shuō)別人了,這樣寫會(huì)挨打的。所以為了避免這種尷尬的事情發(fā)生,一定要增加你代碼的可讀性。
代碼注釋分單行和多行注釋, 單行注釋用#,多行注釋可以用三對(duì)雙引號(hào)""" """
下面給大家看一段標(biāo)準(zhǔn)代碼的注釋,忽略代碼意思
def subclass_exception(name, parents, module, attached_to=None):
"""
Create exception subclass. Used by ModelBase below.
If 'attached_to' is supplied, the exception will be created in a way that
allows it to be pickled, assuming the returned exception class will be added
as an attribute to the 'attached_to' class.
"""
class_dict = {'__module__': module}
if attached_to is not None:
def __reduce__(self):
# Exceptions are special - they've got state that isn't
# in self.__dict__. We assume it is all in self.args.
return (unpickle_inner_exception, (attached_to, name), self.args)
def __setstate__(self, args):
self.args = args
class_dict['__reduce__'] = __reduce__
class_dict['__setstate__'] = __setstate__
return type(name, parents, class_dict)
代碼注釋原則:
不用給全部代碼加注釋,只需要在自己覺(jué)得重要或不好理解的部分加注釋即可
注釋可以用中文或英文,但絕對(duì)不要拼音噢
注釋不光要給自己看,還要給別人看,所以請(qǐng)認(rèn)真寫
添加回答
舉報(bào)