Contenido del Curso
Introduction to GoLang
Introduction to GoLang
Hello World
As a first step, we will start with the conventional "Hello World"
program so that you can get acquainted with the syntax and basic structure of a Go program. Following is the code to output "Hello World"
using Go:
index
package main import "fmt" func main() { fmt.Println("Hello World") }
Here main()
represents a function, indicated by the keyword func
before it.
Note
Keywords, also known as reserved words, are special words with predefined meanings that serve specific purposes in the language. Most of the keywords, like
func
itself, will be explained in detail where relevant. The keywords we will learn in this section arevar
andconst
.
func main()
Everything enclosed within the following curly braces {}
is executed when the program runs. In this case, the fmt.Println
statement is the first thing to execute.
index
func main() { fmt.Println("Hello World") }
fmt.Println
prints whatever is inside the double quotes (") to the console, which in this case is "Hello World". Textual data is always enclosed in double quotation marks (").
Note
Commas
,
can be used in thefmt.Println
statement to output multiple pieces of numerical or textual data. Spaces are automatically added between the values.
index
package main import "fmt" func main() { fmt.Println("I have", 2, "cats at home") }
Detailed explanations of the remaining code components will be provided in later chapters as they become relevant.
¡Gracias por tus comentarios!