当前位置:网站首页>[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") }}
边栏推荐
- registers (assembly language)
- 【愚公系列】2022年07月 Go教学课程 016-运算符之逻辑运算符和其他运算符
- Jetpack Compose学习(8)——State及remeber
- 从两个易错的笔试题深入理解自增运算符
- 封装、获取系统用户信息、角色及权限控制
- Jmeter参数传递方式(token传递,接口关联等)
- Game mall table establishment
- How to solve types joiplay simulator does not support this game
- pytorch bilinear interpolation
- [Meng Xin problem solving] Delete the Nth node from the bottom of the linked list
猜你喜欢
Gabor filter study notes
DNS解析过程【访问网站】
Strict Mode for Databases
WEB安全基础 - - -漏洞扫描器
SWM32系列教程6-Systick和PWM
Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
.NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
【Multithreading】
DNS resolution process [visit website]
In-depth understanding of the auto-increment operator from two error-prone written test questions
随机推荐
.NET Cross-Platform Application Development Hands-on Tutorial | Build a Kanban-style Todo App with Uno Platform
Xss target drone training [success when pop-up window is realized]
Strict Mode for Databases
SWM32系列教程6-Systick和PWM
binglog日志追踪:数据备份并备份追踪
【Multithreading】
Installation considerations for pytorch
ES 中时间日期类型 “yyyy-MM-dd HHmmss” 的完全避坑指南
The difference between truncate and delete in MySQL database
web漏洞之需要准备的工作
45. [Application of list linked list]
对象集合去重的方法
background对float的子元素无效
Asser uses ant sword to log in
How to install joiplay emulator rtp
registers (assembly language)
MySQL筑基篇之增删改查
How to solve the error of joiplay simulator
The first level must project independently
xss靶机训练【实现弹窗即成功】