Methods of payment Abuse

Go programming language basics

27.11.2022, 01:15

In this article, we will tell you how to work with variables and structures. This is especially useful material for novice users. Recall that the language has static typing. In Python, Ruby or JavaScript you will have to perform several correctness checks. Go avoids this problem.

Go language basics

Let's consider the first example:

Go programming language basics

A new function, print, is responsible for the output. Here you can see that you need to pass astring to it. A variable of string type will be created in the main function. It will be passed to print. If we pass it otherwise, we will get an error. You can change the type of the variable to int, you will get an error:

cannot use "Hello World!" (type string) as type int in assignment

Go programming language basics

You will also get an error if you have declared a variable or imported a package but are not using it. There are many more things you can do with Go, one of them is structures. Let's complicate our program by creating a site structure, with name and url fields, which will describe some site:

Go programming language basics

The structure will have a print method that outputs "Welcome...". In main, we initialized the structure and assigned values to its fields, and then called the print method.

The Go programming language is characterized by a number of features and capabilities. We have seen for ourselves.