[Go Language Learning] 1. Getting Started, Basic Grammar and Data Types

Tip: Recently, I want to learn GO language on a whim, and record my learning


foreword

Go is an open source programming language that makes it easy to construct simple, reliable, and efficient software.

1. What is Go?

Go was developed by Robert Griesemer, Rob Pike, and Ken Thompson at the end of 2007, and later joined Ian Lance Taylor, Russ Cox, etc., and finally open sourced in November 2009, and released Go 1 stable in early 2012 Version. Go development is now completely open and has an active community.

 

2. Environment

 

Because I usually use ideas to write java, and I am used to the shortcut keys of Intellij, so I use their GoLand to write code

Step 1: Download Go from the Go language Chinese website

Download Go - Go Chinese Network Go Language Chinese Network golang

After the installation is complete, set the Path  environment variable in the window environment variable 

Step 2: Download GoLand from Intellij official website

Because the individual is a student, it can be used for free

3. Getting Started

1. Code structure

code example


package main //1.声明包,package main表示一个可独立执行的程序

import "fmt" //2.定义包,告诉 Go 编译器这个程序需要使用 fmt 包(实现输入、输出的一个包)

func main(){ //3.执行main函数

  fmt.Println("Hello, World!") //4.语句表达式

}

The general structure is as above, it should be noted that:

1. The P in fmt.Println will only be visible to the outsourcing (fmt) when it is capitalized. This is called **export**. If it is lowercase, it will be invisible to the outside of the package (execution will error), but they are visible and available inside the entire package. 
2. "{" curly braces cannot start a line alone 
3. Comments can use // or /**/

2. Basic grammar

  1. Tags
    Go programs can consist of multiple tags, which can be keywords, identifiers, constants, strings, symbols.
  2. Line separator
    Just write multiple lines directly
    Example:
fmt.Println(xxx)//Println represents the newline 
fmt.Println(xxxx)
  1. Comments
    are commonly used // and /**/
  2. Identifiers
    are used to name variables and program entities; the first character can only be a letter or an underscore cannot be a number and cannot start keywords and operators
  3. String concatenation
    is achieved with '+'
  4. keywords
  5. Space
    example var age int
    and: add spaces between variables and operators, it looks more comfortable
  6. The format string
    uses fmt.Printf to output the content to be output in the specified format

3. Data type

  1. Boolean
    true, false
  2. number type
      • int integer (signed)
      • unit integer (unsigned)
      • float32 32-bit floating point number
      • float64 64-bit floating point number
      • Complex64 32-bit real and imaginary numbers
      • Complex128 64-bit real and imaginary numbers
  1. The string
    string uses UTF-8 encoding to identify Unicode text
  2. Derived category
    commonly used +
      • pointer type ptr
      • number type
      • Structure type struct
      • Channel type chan, ch
      • function type
      • slice type (array-like)
      • Interface type (interface)
      • map type (collection)
  1. other
    + byte like uint8
    + rune like int32

Summarize

Tip: Here is a summary of the article:
For example: the above is what I will talk about today. This article only briefly introduces the use of pandas, and pandas provides a large number of functions and methods that allow us to process data quickly and easily.

Guess you like

Origin blog.csdn.net/SiTiATech/article/details/128750138