Go Language Basics - Operators

Operator for performing mathematical or logical operations at runtime.

Operators

Go operators are built into the language:

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Bitwise Operators
  5. Assignment Operators

Arithmetic operators

    Note: ++ (increment) and --(decrement) Go is a single statement in the language, not the operator.

Operators

description

+ Adding
- Subtraction
* Multiplied
/ Divided
% Phase I

Relational Operators

Operators

description

== Check the two values ​​are equal, equal returns True if otherwise False.
!= Check the two values ​​are not equal, not equal returns True if otherwise False.
  > Check the left value is greater than the right value, it returns True if it is otherwise False.
>= Check the left value is greater than or equal to the right value, it returns True if it is otherwise False.
  < Check the left value is less than the right value, returns True if it is otherwise False.
<=

Check the left value is less than or equal to the right value, returns True if it is otherwise False.

Logical Operators

Operators

description

  &&

Logical AND operator. If both sides of the operands are True, compared to True, otherwise False.

   ||

Logical OR operator. If the number of operations on both sides of a True, compared to True, otherwise False.

    !

Logical NOT operator. If the condition is True, it was False, otherwise True.

Bitwise Operators

Bitwise operators of integer bits in the memory operation.

Operators

description

&

And two binary phase number corresponding to each of the participating operation. (Only two are 1 to 1)

|

Two involved in computing the number corresponding to each phase, or binary. (Two have a 1 on 1)

^

Two involved in computing the number corresponding to the respective binary or different, when two dissimilar corresponding binary, the result is 1. (Two are not the same, compared with 1)

<<

N-bit left shift is multiplied by 2 ^ n. "A << b" is the whole of a respective binary b-bit left shift, the high discard, low 0s.

>>

Right by n bits is divided by 2 ^ n. "A >> b" is a whole to the right of each binary bit b.

Assignment Operators

Operators

description

=

Simple assignment operator, the value of the expression of a value assigned to a left

+=

Added together before assignment

-=

After subtraction assignment

*=

相乘后再赋值

/=

相除后再赋值

%=

求余后再赋值

<<=

左移后赋值

>>=

右移后赋值

&=

按位与后赋值

|=

按位或后赋值

^=

按位异或后赋值







归类 : Go语言

Guess you like

Origin www.cnblogs.com/lz1996/p/12109298.html