English 中文(简体)
什么是Go对等的“is”经营者?
原标题:What is the Go equivalent of Python s "is" operator?

我如何确定2个变量指的是在Go的相同情况? 更具体地说,变数对一个变量的价值也会影响其他变量的价值。

3. 进一步完善问题: 我将如何确定2个变量何时能满足每个CPython的“is”经营者的需要:

a is b
最佳回答

在沙尔,all数值指物体(即点人)。 你们永远不会把物体本身当作一种价值。 <代码>s的操作者比较了两个数值,即点值;而=的操作者比较了两个这样的点,以达到所标明的物体的平等。

在戈里,它变得更加复杂。 Go有点人和其他非点人类型(豆类、号码类型、座标、阵列、斜体、功能、接口、地图、通道)。 要求非指定类别的人平等是不明智的。 (这意味着什么?) 它能做些什么?

因此,要把同样的局势作为沙捞越,就把我们的所有价值观放在点上,因此所有变量都是点。 (许多戈文图书馆的“新”功能是公约,创造了一个点;方法也按点类型操作;因此与公约相符。) 然后(如果ab为点人)a = b 政府将比较两个这样的点点,以便点人平等;如果基础值是可比的,则你可使用a = *b来比较这些数值。

Go also has several non-pointer reference types: slices, maps, functions, and channels. Channels are comparable using == for whether they are the same channel. However, slices, maps, and functions cannot be compared; it may be possible using reflection though.

问题回答

EDIT :我不知道你想要什么。 如果涉及变数平等或变值特性。 答案是第二个(“2个变量是指“价值”相同的情况)。 如果我误解,我就删除这一答案。

我想,=是你想要的。

如果是点名,那么a=b就是指点名和点名。

The following programprints false:

package main

import "fmt"

type test struct {
    a int
}

func main() {

    b := &test{2}
    c := &test{2}
    fmt.Println(c == b)

}

印本<代码>true:

    b := &test{2}
    c := b
    fmt.Println(c == b)

c=b是改变c.a 变化的充分条件。

在非接口和非功能类型的情况下,可以比较平等点。 非点类型不能分享事例,即OTOH。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签