Go language basic types and constant usage examples

  • Foundation type
    • summary
    • There are several data types by category
      • value type
      • Derived type
  • variable
    • summary
      • Single variable declaration
      • Multiple variable declarations

Foundation type

Go language basic types and constant usage examples


In the go programming language, data types are used to declare functions and variables. When the data type appears, in order to divide the data into large data, it is necessary to apply for large memory, so as to make full use of column memory.

There are several data types by category

value type


Bool: Boolean values can only be constants true or false, and the default value is false.

String type

String: the encoding is unified as UTF-8 encoding to identify Unicode text, and the default value is empty string.

Integer (default is 0)

Uint8: unsigned 8-bit integer (0 ~ 255);

Uint16: unsigned 16 bit integer (0 ~ 65535);

Uint32: unsigned 32-bit integer (0 ~ 4294967295);

Uint64: unsigned 64 bit integer (0 ~ 18446744073709551615);

Int8: signed 8-bit integer (- 128 ~ 127);

Int16: signed 16 bit integer (- 32768 ~ 32767);

Int32: signed 32-bit integer (- 2147483648 ~ 2147483647);

Int64: signed 64 bit integer (- 9223372036854775808 ~ 9223372036854775807)

Floating point (default is 0)

Float32: IEEE-754 32-bit floating point number;

Float64: IEEE-754 64 bit floating point number;

Complex64: 32-bit real and imaginary numbers;

Complex128: 64 bit real and imaginary numbers;

Other value types

Byte: similar to uint8;

Run: similar to int32;

Uint: 32 or 64 bit;

Int: same size as uint;

Uintptr: unsigned integer, used to store a pointer;

Derived type

Pointer type (pointer)
Array type
Structured type (struct)
Channel type (channel)
Function type (func)
Slice type (slice)
Interface type
Map type (map)



A constant is a constant value relative to a variable and cannot be modified again, such as pi.

Single variable declaration

const pi = 3.141592
const e = 2.718281

The declaration of constants is very similar to that of variables, except that VaR is replaced by const.

Multiple variable declarations

const (
    pi = 3.141592
    e = 2.718281

Constants can be used for array declarations because they are determined at compile time

const size = 4
var arr [size]int

The above is the details of the usage examples of go language basic types and constants. For more information about go language basic types and constants, please pay attention to other related articles of developeppaper!

Recommended Today

Big data Hadoop — spark SQL + spark streaming

catalogue 1、 Spark SQL overview 2、 Sparksql version 1) Evolution of sparksql 2) Comparison between shark and sparksql 3)SparkSession 3、 RDD, dataframes and dataset 1) Relationship between the three 1)RDD 1. Core concept 2. RDD simple operation 3、RDD API 1)Transformation 2)Action 4. Actual operation 2)DataFrames 1. DSL style syntax operation 1) Dataframe creation 2. SQL […]