go language[1]-basic

1. Go language structure

The basic components of the Go language are as follows:

  • package declaration
  • import package
  • function
  • variable
  • Statements & Expressions
  • Notes
  1. The first line of code package main defines the package name. You must indicate which package the file belongs to in the first uncommented line of the source file, eg: package main. package main represents an independently executable program, and every Go application contains a package named main.
  2. The next line import "fmt" tells the Go compiler that this program needs to use the fmt package (of functions, or other elements), which implements functions for formatting IO (input/output).
  3. The next line, func main(), is the function where the program starts executing. The main function is necessary for every executable program, and is generally the first function to be executed after startup (if there is an init() function, this function will be executed first).
  4. The next line /*...*/ is a comment and will be ignored during program execution. Single-line comments are the most common form of comments, and you can use single-line comments starting with // anywhere. Multi-line comments are also called block comments. They all start with /* and end with */, and cannot be nested. Multi-line comments are generally used for package documentation descriptions or code snippets that are commented into blocks.
  5. The next line, fmt.Println(...), prints the string to the console and automatically adds a newline character \n at the end. The same result can be obtained with fmt.Print("hello, world\n") . 
  6. The functions Print and Println also support the use of variables, eg: fmt.Println(arr). If not specified, they output the variable arr to the console in the default print format.
  7. When identifiers (including constants, variables, types, function names, structure fields, etc.) begin with an uppercase letter, such as: Group1, then objects using this form of identifier can be used by code in external packages (customers side programs need to import the package first), this is called export (like public in object-oriented languages); identifiers that start with a lowercase letter are not visible outside the package, but they are visible inside the entire package and available (like protected in object-oriented languages).

2. Basic data types

  • plastic
    • int uint 32-bit or 64-bit depending on platform
    • int8 uint8
    • int16 uint16
    • uint32 uint32
    • uint64 uint 64
  • floating point
    • float32
    • float84
  • plural
  • boolean
    • true false
  • string
  • constant
    • itoa

3. Operators




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325983141&siteId=291194637