Introduction
Operators help us do math and make decisions in programs easily. They let us add, compare, and combine values quickly.
Operators help us do math and make decisions in programs easily. They let us add, compare, and combine values quickly.
result = value1 operator value2
sum := 5 + 3
isEqual := (a == b)
isValid := (x > 10 && y < 20)
This program uses operators to add, subtract, and compare two numbers. It prints the results so you can see how operators work.
package main import "fmt" func main() { a := 10 b := 20 sum := a + b diff := b - a isEqual := (a == b) isAGreater := (a > b) fmt.Println("Sum:", sum) fmt.Println("Difference:", diff) fmt.Println("Are a and b equal?", isEqual) fmt.Println("Is a greater than b?", isAGreater) }
Operators make code shorter and easier to read.
Using the wrong operator can cause bugs, so check carefully.
Operators let you do math and comparisons in code.
They help make decisions and change values quickly.
Using operators correctly is key to writing good programs.
Operators help us to:var sum = 5 ? 3+ is used to add two numbers.5 + 3 correctly adds the two numbers to get 8.package main
import "fmt"
func main() {
a := 10
b := 3
fmt.Println(a % b)
}a % b is 1.package main
import "fmt"
func main() {
x := 5
y := 10
if x = y {
fmt.Println("Equal")
}
}= which assigns y to x instead of comparing them.== to compare values in Go if statements.if x?10 && x?20 { println("In range") }
Pass the test and this pattern moves unknown