Python 类编码风格

1.命名

  • 类名:(1)单词首字母均大写 (2)不使用下划线
  • 实例名+模块名:(1)小写格式 (2)下划线分隔单词

2.文档字符串

  • 三引号:“““ ”””
  • 每个类定义后面需要包含一个文档字符串,描述类的功能
  • 每个模块里需要包含一个文档字符串,对其中的类功能进行描述

3.import语句

  • 导入标准库模板的import语句  | 中间空一行 | 导入自定义的模板的import语句

4.示例

import random
import collections

import car
import icecreamstand

class IceCeamStand():
    """ the using of class"""
    def __init__(self,……):
         print(……)  
       
    def describe_info():
         print(……)    


class Car():
   """the using of class"""
    def __init__(self,……):
         print(……)  
       
    def describe_info():
         print(……)    

  

猜你喜欢

转载自www.cnblogs.com/paulprayer/p/10552310.html