当前位置:网站首页>[Yugong Series] July 2022 Go Teaching Course 015-Assignment Operators and Relational Operators of Operators
[Yugong Series] July 2022 Go Teaching Course 015-Assignment Operators and Relational Operators of Operators
2022-07-31 00:23:00 【HUAWEI CLOUD】
一、赋值运算符
赋值运算符的分类:
- 基本赋值运算符:基本的赋值运算符是“=”.一开始可能会以为它是“等于”,其实不是的.它实际上意味着把右边表达式的值赋给左边的运算数.
- 复合赋值运算符:复合的赋值运算符,又称为带有运算的赋值运算符,也叫赋值缩写.比如:+=、-=、*=、/=、%=.
1.赋值运算符的概念
运算符 | 说明 | 示例 |
---|---|---|
= | 普通赋值 | c = a + b 将 a + b 表达式结果赋值给 c |
+= | 相加后再赋值 | c += a 等价于 c = c + a |
-= | 相减后再赋值 | c -= a 等价于 c = c - a |
*= | 相乘后再赋值 | c *= a 等价于 c = c * a |
/= | 相除后再赋值 | c /= a 等价于 c = c / a |
%= | 求余后再赋值 | c %= a 等价于 c = c % a |
相关案例:
package mainimport "fmt"func main() { var a = 10 fmt.Println("a=",a) a += 2 fmt.Println("a += 2,a=",a) a -= 2 fmt.Println("a -= 2,a=",a) a *= 2 fmt.Println("a *= 2,a=",a) a /= 2 fmt.Println("a /= 2,a=",a) a %= 2 fmt.Println("a %= 2,a=",a)}
二、关系运算符
关系运算符,有6种关系,分别为小于、大于、小于等于、大于等于、等于、不等于.
1.关系运算符的概念
运算符 | 说明 | 示例 |
---|---|---|
== | 检查两个值是否相等,如果相等返回 True 否则返回 False | (A == B) 为 False |
!= | 检查两个值是否不相等,如果不相等返回 True否则返回 False | (A != B) 为 True |
> | 检查左边值是否大于右边值,如果是返回 True否则返回 False | (A > B) 为 False |
< | 检查左边值是否小于右边值,如果是返回 True 否则返回 False | (A < B) 为 True |
>= | 检查左边值是否大于等于右边值,如果是返回 True 否则返回 False | (A >= B) 为 False |
<= | 检查左边值是否小于等于右边值,如果是返回 True否则返回 False | (A <= B) 为 True |
相关案例:
package mainimport "fmt"func main() { var a int = 21 var b int = 10 if a == b { fmt.Printf("第一行 -a 等于 b\n") } else { fmt.Printf("第一行 -a 不等于 b\n") } if a < b { fmt.Printf("第二行 -a 小于 b\n") } else { fmt.Printf("第二行 -a 不小于 b\n") } if a > b { fmt.Printf("第三行 -a 大于 b\n") } else { fmt.Printf("第三行 -a 不大于 b\n") } a = 5 b = 20 if a <= b { fmt.Printf("第四行 -a 小于等于 b\n") } if b >= a { fmt.Printf("第五行 -a 大于等于 b\n") }}
边栏推荐
- MySQL Series 1: Account Management and Engine
- MySQL数据库(基础)
- The difference between truncate and delete in MySQL database
- Mysql体系化之JOIN运算实例分析
- Necessary artifacts - AKShare quants
- 【愚公系列】2022年07月 Go教学课程 016-运算符之逻辑运算符和其他运算符
- Xss target drone training [success when pop-up window is realized]
- A complete guide to avoiding pitfalls for the time-date type "yyyy-MM-dd HHmmss" in ES
- MySQL table design for message queue to store message data
- 寄存器(汇编语言)
猜你喜欢
【唐宇迪 深度学习-3D点云实战系列】学习笔记
h264和h265解码上的区别
Understand from the 11 common examples of judging equality of packaging types in the written test: packaging types, the principle of automatic boxing and unboxing, the timing of boxing and unboxing, a
pytorch bilinear interpolation
Machine Learning 1-Regression Model (2)
In-depth understanding of the auto-increment operator from two error-prone written test questions
Regular expression password policy and regular backtracking mechanism bypass
Meeting OA project pending meeting, all meeting functions
Oracle一个诡异的临时表空间不足的问题
MySQL的触发器
随机推荐
ES 中时间日期类型 “yyyy-MM-dd HHmmss” 的完全避坑指南
MySQL数据库的truncate与delete区别
Necessary artifacts - AKShare quants
Jetpack Compose学习(8)——State及remeber
MySQL的触发器
How to install joiplay emulator rtp
Installation considerations for pytorch
ES6中 async 函数、await表达式 的基本用法
【深入浅出玩转FPGA学习13-----------测试用例设计1】
Shell编程之条件语句
Regular expression password policy and regular backtracking mechanism bypass
乌克兰外交部:乌已完成恢复粮食安全出口的必要准备
网络常用的状态码
MySQL数据库约束,表的设计
加密传输过程
joiplay模拟器rtp如何安装
what is jira
Dry goods | 4 tips for MySQL performance optimization
joiplay模拟器不支持此游戏类型怎么解决
Common network status codes