Home  >  Article  >  Backend Development  >  A brief analysis of operators in Golang

A brief analysis of operators in Golang

青灯夜游
青灯夜游forward
2022-11-24 21:21:206384browse

This article will teach you about Golang and talk about the operators in the basics of Go language. I hope it will be helpful to you.

A brief analysis of operators in Golang

The built-in operators in Go language are:

  • Arithmetic operators

  • Relational operators

  • Logical operators

  • Assignment operators

  • Bitwise operators

For friends who have experience with other programming languages, it is still very simple to learn. Basically watching it once is enough. 【Related recommendations: Go video tutorial

1. Arithmetic operators

| + | 相加 
| - | 相减 
| * | 相乘 
| / | 相除 
| % | 求余

2. Relational operators

| == | 检查两个值是否相等,如果相等返回 True 否则返回 False。     
| != | 检查两个值是否不相等,如果不相等返回 True 否则返回 False。   
| >  | 检查左边值是否大于右边值,如果是返回 True 否则返回 False。   
| >= | 检查左边值是否大于等于右边值,如果是返回 True 否则返回 False。 
| <  | 检查左边值是否小于右边值,如果是返回 True 否则返回 False。   
| <= | 检查左边值是否小于等于右边值,如果是返回 True 否则返回 False。

3. Logical operators

| && | 逻辑 AND 运算符。 如果两边的操作数都是 True,则为 True,否则为 False。 

| || | 逻辑 OR 运算符。 如果两边的操作数有一个 True,则为 True,否则为 False。 

| !  | 逻辑 NOT 运算符。 如果条件为 True,则为 False,否则为 True。

4. Assignment operators

| =   | 简单的赋值运算符,将一个表达式的值赋给一个左值 
| +=  | 相加后再赋值                  
| -=  | 相减后再赋值                  
| *=  | 相乘后再赋值                  
| /=  | 相除后再赋值                  
| %=  | 求余后再赋值                  
| <<= | 左移后赋值                    
| >>= | 右移后赋值                    
| &=  | 按位与后赋值                  
| |=  | 按位或后赋值                  
| ^=  | 按位异或后赋值

5. Bit operator

| &  | 参与运算的两数各对应的二进位相与。 (两位均为1才为1)                   
| |  | 参与运算的两数各对应的二进位相或。 (两位有一个为1就为1)                 
| ^  | 参与运算的两数各对应的二进位相异或,当两对应的二进位相异时,结果为1。 (两位不一样则为1) 
| << | 左移n位就是乘以2的n次方。 “a<<b”是把a的各二进位全部左移b位,高位丢弃,低位补0。 
| >> | 右移n位就是除以2的n次方。 “a>>b”是把a的各二进位全部右移b位。

End:

Remind me again, students who need to join the Technical Exchange Group can add me on WeChatfangdongdong_25, those who need to join the front-end engineer exchange group remark "front-end" , those who need to join the go back-end exchange group remark "go back-end"

For more programming-related knowledge, please visit: programming video! !

The above is the detailed content of A brief analysis of operators in Golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete
Previous article:Does go language have gc?Next article:Does go language have gc?