Code with Go
Ask or search…
K
Links

Values

This section demonstrates basic string concatenation, arithmetic operations, and boolean logic. Let's break it down step by step:
// Package declaration - Every Go program starts with a package declaration.
package main
// Importing the "fmt" package - It provides functions for formatting and printing.
import "fmt"
// The main function - It is the entry point of the program.
func main() {
// Print the concatenated string "go" + "lang"
fmt.Println("go" + "lang")
// Print the result of the arithmetic operation 1+1
fmt.Println("1+1 =", 1+1)
// Print the result of the arithmetic operation 7.0/3.0
fmt.Println("7.0/3.0 =", 7.0/3.0)
// Print the result of the boolean operation true && false (logical AND)
fmt.Println(true && false)
// Print the result of the boolean operation true || false (logical OR)
fmt.Println(true || false)
// Print the result of the boolean operation !true (logical NOT)
fmt.Println(!true)
}

Output

golang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false
Now, let's go through each part:
  1. 1.
    Package Declaration:
    package main
    • In Go, every program starts with a package declaration. The main package is a special package that serves as the entry point for the executable programs.
  2. 2.
    Import Statement:
    import "fmt"
    • This line imports the "fmt" package, which provides functions for formatting and printing text.
  3. 3.
    Main Function:
    func main() {
    • The main function is the entry point of the program. Execution of the program begins here.
  4. 4.
    String Concatenation:
    fmt.Println("go" + "lang")
    • This line prints the concatenated string "go" + "lang" using the Println function from the "fmt" package.
  5. 5.
    Arithmetic Operations:
    fmt.Println("1+1 =", 1+1)
    fmt.Println("7.0/3.0 =", 7.0/3.0)
    • These lines print the results of simple arithmetic operations. The first line prints the sum of 1 and 1, and the second line prints the result of dividing 7.0 by 3.0.
  6. 6.
    Boolean Logic:
    fmt.Println(true && false)
    fmt.Println(true || false)
    fmt.Println(!true)
    • These lines demonstrate boolean logic. The first line prints the result of the logical AND operation between true and false. The second line prints the result of the logical OR operation. The third line prints the result of the logical NOT operation on true.
  7. 7.
    Closing Brace:
    }
    • The closing brace marks the end of the main function.
This Go program thus introduces string concatenation, arithmetic operations, and boolean logic using the basic features of the language. It's a simple and concise example to get started with Go programming.