Vscode开发python运算符(__iter__等)重载自动提示

        Vscode相对于Pycharm简直是轻量,但是代码自动提示也弱了很多,比如pylance就没有支持运算符重载函数(__iter__、__next__()、__add__()等)的自动完成提示。    

       废话不多说,直接上解决方案:

        1.    File->Preference->User Snippets->python.json

        2.     在编辑框中输入一下内容

        

{
	// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	"def __del__(self):": {
		"prefix": "def __del__(self):",
		"body": [
			"def __del__(self):",
			"\t'''析构函数,其功能是销毁对象时进行回收资源的操作'''",
			"\t$2"
		]
	},
	"def __add__(self, other):": {
		"prefix": "def __add__(self, other):",
		"body": [
			"def __add__(self, other):",
			"\t'''加法运算符 +,当类对象 X 做例如 X+Y 或者 X+=Y 等操作,内部会调用此方法。但如果类中对 __iadd__ 方法进行了重载,则类对象 X 在做 X+=Y 类似操作时,会优先选择调用 __iadd__ 方法。'''",
			"\t$2"
		]
	},
	"def __radd__(self, other):": {
		"prefix": "def __radd__(self, other):",
		"body": [
			"def __radd__(self, other):",
			"\t'''当类对象 X 做类似 Y+X 的运算时,会调用此方法。'''",
			"\t$2"
		]
	},
	"def __iadd__(self, other):": {
		"prefix": "def __iadd__(self, other):",
		"body": [
			"def __iadd__(self, other):",
			"\t'''析构重载 += 运算符,也就是说,当类对象 X 做类似 X+=Y 的操作时,会调用此方法。函数'''",
			
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值