Golang:基础图解

作者: 与蟒唯舞 | 来源:发表于2017-12-05 10:03 被阅读4次
常用 go 命令
编译 / 执行代码
包相关
零值
自定义类型
函数接收者

Now, any variable of type "deck" now get access to the "print" method.

package main

import "fmt"

type deck []string

/*
func (this deck) print() {}
func (self deck) print() {}

While the code is technically valid and will compile, we don't ever reference a receiver value as 'this' or 'self'
Go avoids any mention of 'this' or 'self'
*/
func (d deck) print() {
    for i, card := range d {
        fmt.Println(i, card)
    }
}

func main() {
    cards := deck{"Ace of Spades", "Two of Spades"}
    cards.print()
}
切片
字节切片

相关文章

网友评论

    本文标题:Golang:基础图解

    本文链接:https://www.haomeiwen.com/subject/wblfvxtx.html