本文介绍了= + Python运算符在语法上是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心写了:

total_acc =+ accuracy

代替:

total_acc += accuracy

我在网上搜索,找不到任何东西.那么发生了什么,为什么Python认为我的意思是我要输入的内容?

I searched the net and could not find anything. So what happened, why does Python think I mean what I am typing?

推荐答案

这与您要像total_acc = -accuracy一样,只不过是正面的而不是负面的.不过,它基本上与total_acc = accuracy相同,因为在值之前添加+不会更改它.

This is the same as if you were to do like total_acc = -accuracy, except positive instead of negative. It basically is the same as total_acc = accuracy though, as adding a + before a value does not change it.

这称为一元运算符,因为只有一个参数(例如:+a)而不是两个参数(例如:a+b).

This is called an unary operator as there is only one argument (ex: +a) instead of two (ex: a+b).

此链接对其进行了详细说明.

This link explains it a little more.

这篇关于= + Python运算符在语法上是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 09:43