go -- Language Fundamentals

2020/02/23


Main Concepts Data Type

  1. 25个key words。变量命名以字母或下划线开头。但是不推荐_出现在中间。
  2. 声明和赋值:
    ex:var name string = “darcy”
        var name string–声明 name = `darcy`–赋值
        var name = `darcy`
        var (
             name1 = “darcy”//没有";"
             name2 = “lizzy”
             )
        firstName := “darcy”–声明and赋值(推荐);
        x,y,x := 1,2,3–多变量分别声明赋值
        x,y := y,x–exchange
go’s typesbasicaggregatereferenceinterface
ex:numbers,strings and booleansarreys,structspointers,slices,maps,functions and channels
  1. string中的"“和’’,``作用不同”/n/n"会被转义,``不会,而’'表示rune literal(码点字面量,类型int32)
  2. string是immutable. 变量名仅相当于一个指针, 所以也不能进行修改(s[0]=‘a’ ,报错,但是s += 'a’可)
  3. zero values:0,false,"",nil(for slice pointer map channel function.etc)
  4. 词汇基础
    注释:// /* */
    key words:break default func if .etc
    operator and punctuation:+ - & += := .etc
    boolean type: true false
    numeric type:int int8 uint float32 complex64 byte rune .etc
    array type: [10] int []32 byte
    slice type:make([]int, 50, 100)
    struct type: struct{string name, int age}
  5. operator orders:从上到下
    * / % << >> & &^
    + - | ^
    == != < <= > >=
    &&
    ||
    btw: &:bitwise AND
         |: bitwise OR
         ^: bitwise XOR
         &^: bit clear (AND NOT)
         <<: left shift【var x unit8 = 2;x = x << 1;fmt.Printf("%08b",x) 输出:00000100】
         >>: right shift
  6. 输出变量(print verbs):
    %v: struct
    %T: show type
    %d: uint int.etc
    %t: bool
    %g(%5.1f.etc ): float32 complex64 etc.
    %s: string
    %p: chan
    %pointer %P
    %b: 二进制表示
    %o: 八进制
    %x: 十六进制表示
    %q: []rune【fmt.Printf("%q", []rune(“nice”)) 输出:[‘n’,‘i’,‘c’,‘e’]】

other things

  1. fmt.Println(“good Day[5]”): 输出为D的ascii(68)
  2. fmt.Printf("%3d %8b %08b", 2, 2, 2)输出:
      2       10 00000010
  3. 和NaN作比较永远为false
  4. s := “hello好”;fmt.Println(len(s));fmt.Printlin(utf8.RuneCountInString(s)) 输出:9和6
  5. scope(作用域):
typelocal-levelglobal-level
scopeown blockfile:lowercase:anywhere in the file;package:uppercase:anywhere within the package
lifetimeend of the enclosing blockthe entire execution of the program

{}in the proceding code is called a “syntactic block”,一个{}即为一块(stack)
当然还有lexical block,包括explicit和implicit block

  1. const (
    a = iota
    _
    b = iota
    );fmt.Printf("%d %d", a, b)
    输出:0 2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值