当前位置:网站首页>[Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
[Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
2022-07-31 00:23:00 【HUAWEI CLOUD】
一、逻辑运算符
用于连接多个条件,一般来讲就是关系表达式,最终的结果也是一个 bool 值.
1.逻辑运算符的概念
| 运算符 | 说明 | 示例 |
|---|---|---|
| && | 逻辑 AND 运算符.如果两边的操作数都是 True,则条件 True,否则为 False | (A && B) 为 False |
| II | 逻辑 OR 运算符.如果两边的操作数有一个 True,则条件 True,否则为 False | (A II B) 为 True |
| ! | 逻辑 NOT 运算符.如果条件为 True,则逻辑 NOT 条件 False,否则为 True | !(A && B) 为 True |
相关案例:
package mainimport "fmt"func main() { var a bool = true var b bool = false if a && b { fmt.Printf("第一行 - 条件为 true \n") } if a || b { fmt.Printf("第二行 - 条件为 true \n") } // 修改 a 和 b 的值 a = false b = true if a && b { fmt.Printf("第三行 - 条件为 true \n") } else { fmt.Printf("第三行 - 条件为 false \n") } if !(a && b) { fmt.Printf("第四行 - 条件为 true \n") }}
二、其他运算符
1.位运算符的概念
| 运算符 | 说明 | 示例 |
|---|---|---|
| & | 如果两个操作数中都存在二进制AND运算符,则将其复制到结果. | (A&B)结果为12,也就是0000 1100 |
| I | 二进制OR运算符复制一个位,如果它存在于任一操作数. | (AIB)结果为61,也就是0011 1101 ^ 二进制XOR运算符复制位,如果它在一个操作数中设置,但不是在两个操作数中设置. (A^B)结果为49,也就是0011 0001 |
| << | 二进制左移位运算符.左操作数值向左移动由右操作数指定的位数. | A<<2结果为240,也就是1111 0000 |
| >> | 二进制右移运算符.左操作数值向右移动由右操作数指定位数. | A>>2结果为15,也就是0000 1111 |
2.地址相关运算符的概念
| 运算符 | 说明 | 示例 |
|---|---|---|
| & | 返回变量的地址 | &a将给出变量a的实际地址. |
* | 指向变量的指针 | *a是指向变量a的指针. |
边栏推荐
- A Brief Talk About MPI
- MySQL grant statements
- Shell编程之条件语句
- 软件开发设计流程
- Go 学习笔记(84)— Go 项目目录结构
- The difference between h264 and h265 decoding
- [Tang Yudi Deep Learning-3D Point Cloud Combat Series] Study Notes
- MySQL table design for message queue to store message data
- C语言力扣第48题之旋转图像。辅助数组
- Point Cloud Scene Reconstruction with Depth Estimation
猜你喜欢

Gabor filter study notes

(5) fastai application

.NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App

Error in go mode tidy go warning “all” matched no packages

(五)fastai应用

In-depth understanding of the auto-increment operator from two error-prone written test questions

Axure Carousel

Meeting OA project pending meeting, all meeting functions

加密传输过程

How to solve the error of joiplay simulator
随机推荐
.NET Cross-Platform Application Development Hands-on Tutorial | Build a Kanban-style Todo App with Uno Platform
A Brief Talk About MPI
Method for deduplication of object collection
Word文件损坏如何修复
SereTOD2022 Track2 Code Analysis - Task-based Dialogue Systems Challenge for Semi-Supervised and Reinforcement Learning
Bypass of xss
WEB安全基础 - - -漏洞扫描器
过滤器(Filter)
firewalld
MySQL中substring与substr区别
Xss target drone training [success when pop-up window is realized]
Go 学习笔记(84)— Go 项目目录结构
what is jira
【深入浅出玩转FPGA学习13-----------测试用例设计1】
Kotlin协程:协程上下文与上下文元素
MySql数据恢复方法个人总结
How to use joiplay emulator
What are the efficient open source artifacts of VSCode
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
binglog log tracking: data backup and backup tracking