
Operators in GoLang
Operators in GoLang
In Go, operators are used to perform operations on variables and values. They can be categorized into several types:
1. Arithmetic Operators
These operators are used to perform mathematical calculations.
- +: Addition
- -: Subtraction
- *: Multiplication
- /: Division
- %: Modulus (remainder of division)
Example:
import "fmt"func main() { a, b := package main
import "fmt"func main() { a, b := package main
import "fmt"func main() { package main
import "fmt"func main() { package main
import "fmt"func main() { a, b := package main
import "fmt"func main() { a := package main
import "fmt"func main() { var i interface{} = "Hello, Go!" str, ok := i.(string) if ok { fmt.Println(str) // Output: Hello, Go! }}
Summary of Go Operators:
- Arithmetic Operators:
+
,-
,*
,/
,%
- Relational Operators:
==
,!=
,<
,>
,<=
,>=
- Logical Operators:
&&
,||
,!
- Assignment Operators:
=
,+=
,-=
,*=
,/=
,%=
etc. - Unary Operators:
+
,-
,++
,--
,&
,*
- Bitwise Operators:
&
,|
,^
,~
,<<
,>>
- Type Assertion:
.(T)
Each operator has its specific use case, and understanding how to use them efficiently is key to mastering Go programming.