Go Fast-03-types and variables

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Directory

      • Types and variables
        • Data type
          • Classification
        • Type 0 Value
        • Type aliases
        • Variable
          • Definition and assignment of variables
          • Declaration of multiple variables
            • Variable list
            • Variable group
            • Parallel declarations
        • Type conversions
        • Conversion of characters to numbers

Summary

numeric types, Boolean types, reference types, type 0 values, type aliases, definition variables, type inference, short declarations, type conversions, declarations of multiple variables, conversion of characters to numbers

Types and variables

Data type

Classification

    • Boolean: BOOL
      • True or False
    • Integer: Int/uint-may be 32-bit or 64-bit depending on the platform
    • 8-bit integer: int8/uint8
    • BYTE: Byte (uint8 alias)
    • 16-bit integer: int16/uint16
    • 32-bit integer: Int32/uint32
    • Rune (Int32 alias)
    • 64-bit integer: Int64/uint64
    • Floating point: Float32/float64
    • Plural: complex64/complex128
    • 32 and 64-bit integers sufficient to hold pointers: uintptr-depending on the platform may be 32-bit or 64-bit
    • Other types:
      • Array, struct, string
    • Reference type:
      • Slice, map, channel, interface
    • Interface: interface
    • Function: Func

Type 0 Value

A value of 0 is the default value that a variable is declared to be a type, a value of type 0 bool false , a string of""

Type aliases

type (    float32    string)

Variable

Definition and assignment of variables

Variables var are defined using keywords

//声明varint//赋值a = 123//声明的同时赋值varint = 321

Inferred type by System

var c = 321

Short Declaration variable

d:=321

Declaration of multiple variables

Variable list

//var 语句定义了一个变量的列表;跟函数的参数列表一样,类型在后面。varbool

Variable group

var(    sss,bbb = 1,2)

Parallel declarations

m,n:=13,14

_ Means Ignore

a,_,c,d:=1,2,3,4

Rules

    • All variables can use type inference
    • Global variables can use variable groups
    • Global variables cannot omit Var, that is, you cannot use a short declaration variable
    • Local variables cannot use variable groups

Type conversions

varint = 42varfloat64float64(i)varuintuint(f)

A simpler way

i := 42float64uint(f)

Conversion of characters to numbers

string()instead of converting the number 65 to "65", it becomes the character "A". If you need to switch to "65", you need to use strconv the package Itoa() and Atoi() method

import"strconv"//字符与数字的转换varint = 65fmt.Println(string//Avar//65//65<nil>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.