当前位置:网站首页>[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") }}
边栏推荐
- 【Yugong Series】July 2022 Go Teaching Course 017-IF of Branch Structure
- DATA AI Summit 2022提及到的对 aggregate 的优化
- transition transition && animation animation
- Shell编程之条件语句
- MySQL数据库进阶篇
- IOT cross-platform component design scheme
- How to ensure the consistency of database and cache data?
- [In-depth and easy-to-follow FPGA learning 13---------Test case design 1]
- 【c语言课程设计】C语言校园卡管理系统
- 加密传输过程
猜你喜欢

【唐宇迪 深度学习-3D点云实战系列】学习笔记
![45. [Application of list linked list]](/img/7a/ca026cafeceffd2daee68fe66e1882.png)
45. [Application of list linked list]

C language force buckles the rotating image of the 48th question.auxiliary array

An easy-to-use interface testing tools - the Postman

(五)fastai应用

MySQL数据库(基础)

firewalld

消息队列存储消息数据的MySQL表设计

How to install joiplay emulator rtp

47. 【Pointers and Arrays】
随机推荐
【深入浅出玩转FPGA学习15----------时序分析基础】
MySQL数据库进阶篇
封装、获取系统用户信息、角色及权限控制
Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
数据库的严格模式
【愚公系列】2022年07月 Go教学课程 015-运算符之赋值运算符和关系运算符
Add text watermark to PHP image
常用的正则表达式
xss绕过:prompt(1)
DNS解析过程【访问网站】
【愚公系列】2022年07月 Go教学课程 016-运算符之逻辑运算符和其他运算符
GO GOPROXY代理设置
XSS相关知识
PHP图片添加文字水印
【Yugong Series】July 2022 Go Teaching Course 017-IF of Branch Structure
Common network status codes
mysql主从复制及读写分离脚本-亲测可用
joiplay模拟器rtp如何安装
Redis learning
MySQL数据库约束,表的设计