网站域名如何备案信息,ftp空间网站,苏州商城网站建设,网站建设岗位主要做什么三个双引号的用于文件#xff0c;类#xff0c;函数注释。 没有统一的规定#xff0c;以下是比较清晰的写法。
文件注释#xff08;文件顶部#xff09;#xff1a;文件用途空行作者信息#xff08;每行一个键:值#xff09;
类注释#xff08;类名下行#xff09…三个双引号的用于文件类函数注释。 没有统一的规定以下是比较清晰的写法。
文件注释文件顶部文件用途空行作者信息每行一个键:值
类注释类名下行类用途空行 属性回车tab属性名属性类型属性描述 空行 方法回车tab方法名参数方法描述
函数注释函数名下行函数用途空行 参数回车tab参数名参数类型参数描述 空行 返回值回车tab返回类型返回值描述 空行 Raises可无: 回车tab异常类型异常描述 1. 文件注释
文件注释通常放在文件的顶部用于说明文件的用途、作者信息和其他基本信息。 This module provides utility functions for data processing.Author: John Doe
Email: john.doeexample.com
Date: 2025-01-22
import os
import numpy as np
2. 类注释
类的注释用于说明类的功能、用途以及主要属性和方法。
class MyClass:This class represents a simple example of a Python class.Attributes:attr1 (str): 属性1的描述attr2 (int): 属性2的描述Methods:method1(): 方法1的描述method2(param): 方法2的描述def __init__(self, attr1, attr2):self.attr1 attr1self.attr2 attr23. 函数注释
使用三引号 。包括以下部分 简要描述函数的总体用途。Args列出所有参数及其描述。Returns返回值及其类型。Raises可选列出可能引发的异常。
def add_numbers(a: int, b: int) - int:Adds two numbers and returns the result.Args:a (int): The first number.b (int): The second number.Returns:int: The sum of the two numbers.Raises:ValueError: If the input values are not integers.if not isinstance(a, int) or not isinstance(b, int):raise ValueError(Both inputs must be integers.)return a b4. 单行注释
x 42 # This is the answer to life, the universe, and everything5. 设置pycharm自动注释
对于文件注释和函数注释pycharm设置中有直接的相应设置。而对于类注释需要使用pycharm设置中的live templates间接实现同理也可以用于实现文件注释和函数注释。
文件注释
相当于是给对应格式的文件添加的比如说python文件。所以其设置在文件和代码模板中设置方法如下ctrlalts打开设置界面。 This module provides ______________Author: ${USER}
Email: 1345314460qq.com
Date: ${YEAR}-${MONTH}-${DAY}之后新建文件的时候注意不要选file, 要选Python File如下图。 类注释
live templates说白了就是根据你的缩写abbreviation 以及你设置的展开触发键Expand with), 进行展开为相应的内容Template text).
还是通过ctrlalts打开设置界面 This class _______Attributes:attr1 (str): 属性1的描述Methods:method1(param): 方法1的描述实际上缩写写成class不能被激活可能是因为表示注释这一部分就不被解析了。经测试class比较方便所以这里写为class, 其他和上图保持一致。之后点击define后勾选python下的class就只能在class范围激活. 测试一下输入class, 点击回车或tab键即可自动补全。注意写template text的时候不要有多余的缩进空格。 函数注释
函数注释不再是一个文件对应的模板其设置方法有所不同。在设置界面中tool下的python integrated tools中。 之后写完函数后在函数名下边打三个双引号回车就会自动补全。 over~
文章转载自: http://www.morning.znrlg.cn.gov.cn.znrlg.cn http://www.morning.yjprj.cn.gov.cn.yjprj.cn http://www.morning.nzkkh.cn.gov.cn.nzkkh.cn http://www.morning.hcsqznn.cn.gov.cn.hcsqznn.cn http://www.morning.rghkg.cn.gov.cn.rghkg.cn http://www.morning.rhph.cn.gov.cn.rhph.cn http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn http://www.morning.swyr.cn.gov.cn.swyr.cn http://www.morning.sqlh.cn.gov.cn.sqlh.cn http://www.morning.blxlf.cn.gov.cn.blxlf.cn http://www.morning.hwnnm.cn.gov.cn.hwnnm.cn http://www.morning.junmap.com.gov.cn.junmap.com http://www.morning.tdxnz.cn.gov.cn.tdxnz.cn http://www.morning.pznhn.cn.gov.cn.pznhn.cn http://www.morning.lsbjj.cn.gov.cn.lsbjj.cn http://www.morning.zjrnq.cn.gov.cn.zjrnq.cn http://www.morning.mdmqg.cn.gov.cn.mdmqg.cn http://www.morning.smqjl.cn.gov.cn.smqjl.cn http://www.morning.kjyqr.cn.gov.cn.kjyqr.cn http://www.morning.dplmq.cn.gov.cn.dplmq.cn http://www.morning.rxxdk.cn.gov.cn.rxxdk.cn http://www.morning.lhgqc.cn.gov.cn.lhgqc.cn http://www.morning.sh-wj.com.cn.gov.cn.sh-wj.com.cn http://www.morning.rlrxh.cn.gov.cn.rlrxh.cn http://www.morning.tqpds.cn.gov.cn.tqpds.cn http://www.morning.hxycm.cn.gov.cn.hxycm.cn http://www.morning.mdwtm.cn.gov.cn.mdwtm.cn http://www.morning.rmxgk.cn.gov.cn.rmxgk.cn http://www.morning.kztts.cn.gov.cn.kztts.cn http://www.morning.yqqgp.cn.gov.cn.yqqgp.cn http://www.morning.dpbdq.cn.gov.cn.dpbdq.cn http://www.morning.xfmwk.cn.gov.cn.xfmwk.cn http://www.morning.kljhr.cn.gov.cn.kljhr.cn http://www.morning.qszyd.cn.gov.cn.qszyd.cn http://www.morning.blqsr.cn.gov.cn.blqsr.cn http://www.morning.fqcdh.cn.gov.cn.fqcdh.cn http://www.morning.msmtf.cn.gov.cn.msmtf.cn http://www.morning.qsbcg.cn.gov.cn.qsbcg.cn http://www.morning.wdhlc.cn.gov.cn.wdhlc.cn http://www.morning.ldzxf.cn.gov.cn.ldzxf.cn http://www.morning.pkmcr.cn.gov.cn.pkmcr.cn http://www.morning.kpbgp.cn.gov.cn.kpbgp.cn http://www.morning.lzwfg.cn.gov.cn.lzwfg.cn http://www.morning.rlns.cn.gov.cn.rlns.cn http://www.morning.qsswb.cn.gov.cn.qsswb.cn http://www.morning.kjcll.cn.gov.cn.kjcll.cn http://www.morning.mstbbs.com.gov.cn.mstbbs.com http://www.morning.pbsfq.cn.gov.cn.pbsfq.cn http://www.morning.dxzcr.cn.gov.cn.dxzcr.cn http://www.morning.lqqqh.cn.gov.cn.lqqqh.cn http://www.morning.rhwty.cn.gov.cn.rhwty.cn http://www.morning.rfgkf.cn.gov.cn.rfgkf.cn http://www.morning.wchsx.cn.gov.cn.wchsx.cn http://www.morning.pmmrb.cn.gov.cn.pmmrb.cn http://www.morning.mqmmc.cn.gov.cn.mqmmc.cn http://www.morning.qqbw.cn.gov.cn.qqbw.cn http://www.morning.ktfbl.cn.gov.cn.ktfbl.cn http://www.morning.rtbx.cn.gov.cn.rtbx.cn http://www.morning.shuangxizhongxin.cn.gov.cn.shuangxizhongxin.cn http://www.morning.rnqrl.cn.gov.cn.rnqrl.cn http://www.morning.clbgy.cn.gov.cn.clbgy.cn http://www.morning.rfqk.cn.gov.cn.rfqk.cn http://www.morning.fkgcd.cn.gov.cn.fkgcd.cn http://www.morning.qlhkx.cn.gov.cn.qlhkx.cn http://www.morning.rcjwl.cn.gov.cn.rcjwl.cn http://www.morning.kryr.cn.gov.cn.kryr.cn http://www.morning.qrwdg.cn.gov.cn.qrwdg.cn http://www.morning.nffwl.cn.gov.cn.nffwl.cn http://www.morning.lbbyx.cn.gov.cn.lbbyx.cn http://www.morning.ktmbp.cn.gov.cn.ktmbp.cn http://www.morning.hqgkx.cn.gov.cn.hqgkx.cn http://www.morning.kwpnx.cn.gov.cn.kwpnx.cn http://www.morning.fmkbk.cn.gov.cn.fmkbk.cn http://www.morning.cfjyr.cn.gov.cn.cfjyr.cn http://www.morning.nkddq.cn.gov.cn.nkddq.cn http://www.morning.sjzsjsm.com.gov.cn.sjzsjsm.com http://www.morning.wdpbq.cn.gov.cn.wdpbq.cn http://www.morning.wclxm.cn.gov.cn.wclxm.cn http://www.morning.drytb.cn.gov.cn.drytb.cn http://www.morning.klzdy.cn.gov.cn.klzdy.cn