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} }
兩個結構體可以使用 == 或 != 運算符進行比較,但不支持 > 或 <。
同類型的兩個結構體變量可以相互賦值。