package main import ( "fmt" ) type Student struct { id int name string } func main() { //比较 s1 := Student{1, "yy"} s2 := Student{2, "yang"} s3 := Student{1, "yy"} fmt.Println(s1 == s2) //false fmt.Println(s1 == s3) //true //赋值 var s4 Student s4 = s1 fmt.Println(s4) //{1 yy} }
两个结构体可以使用 == 或 != 运算符进行比较,但不支持 > 或 <。
同类型的两个结构体变量可以相互赋值。