1.算数运算符
和数学中固定运算符差不过
+
-
*
/
%
++
--
注意:Go预言中不允许 ++i --i 这种写法并且i++ i-- 不允许参与运算
i := 1
i++
fmt.Println(i)
i2 := 2
c := i + i2
fmt.Println(c)
// d := i++ + ++i2
2.关系运算符
>
<
>=
<=
==
!=
/**
* @author ly (个人博客:https://www.cnblogs.com/qbbit)
* @date 2023/3/26 20:57
* @tags 喜欢就去努力的争取
*/
package main
import "fmt"
func main() {
a := 2
b := 3
c := 4
d := -1
res1 := a > b
res2 := a < b
fmt.Println(res1)
fmt.Println(res2)
res3 := c == b
res4 := c != d
fmt.Println(res3)
fmt.Println(res4)
}
3.逻辑运算符
逻辑运算符: 操作数必须是bool,运算结果也是bool
逻辑与:&&
- 运算规则:所有的操作数都是真,结果才为真,有一个为假,结果就为假“一假则假,全真才真”
逻辑或:||
- 运算规则;偶有的操作数都是假,结果才为假,有一个为真,结果就为真"一真则真,全假才假”
逻辑非:!
- !T->false
- !F->true
/**
* @author ly (个人博客:https://www.cnblogs.com/qbbit)
* @date 2023/3/26 21:07
* @tags 喜欢就去努力的争取
*/
package main
import "fmt"
func main() {
b1 := true
b2 := false
res1 := b1 && b2
fmt.Println(res1)
res2 := b1 || b2
fmt.Println(res2)
res3 := !b1
fmt.Println(res3)
res4 := !b2
fmt.Println(res4)
}
4.位运算符
5.赋值运算符
运算符的优先级