Algorithm
In the Go programming language, the fmt
package is used for formatted I/O operations, including printing to the standard output. The Println
function is commonly used to print a line of text followed by a newline character.
Code Examples
#1 Code Example with Golang Programming
Code -
Golang Programming
package main
import "fmt"
func main() {
// Print a string
fmt.Println("Hello, Go!")
// Print multiple values
fmt.Println("The answer is", 42)
// Print variables
name := "John"
age := 30
fmt.Println("Name:", name, "Age:", age)
}
In this example:
fmt.Println("Hello, Go!") prints the string "Hello, Go!" followed by a newline.
fmt.Println("The answer is", 42) prints the string "The answer is" followed by the value 42 and then a newline.
fmt.Println("Name:", name, "Age:", age) prints the strings "Name:", "John", "Age:", and the value of the age variable, separated by spaces, followed by a newline.
Copy The Code &
Try With Live Editor
#2 fmt.Print
Code -
Golang Programming
package main
import "fmt"
func main() {
// Print without a newline
fmt.Print("Hello, ")
fmt.Print("Go!")
}
Copy The Code &
Try With Live Editor
#3 Using %g to print Float Values
Code -
Golang Programming
// Program to print an integer using its format specifier %g
package main
import "fmt"
func main() {
var number annualSalary = 65000.5
fmt.Printf("Annual Salary: %g", annualSalary)
}
Copy The Code &
Try With Live Editor
Output
Demonstration
Go Print Statement-Go Lang Programming