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:
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.
Import Statement:
import "fmt"
This line imports the "fmt" package, which provides functions for formatting and printing text.
Main Function:
func main() {
The
main
function is the entry point of the program. Execution of the program begins here.
String Concatenation:
fmt.Println("go" + "lang")
This line prints the concatenated string "go" + "lang" using the
Println
function from the "fmt" package.
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.
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
andfalse
. The second line prints the result of the logical OR operation. The third line prints the result of the logical NOT operation ontrue
.
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.
Last updated
Was this helpful?