Go pkg學與練 - buildin

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。builtin package 包含go語言中的各種類型:<pre><code>unint8, uint16, uint32, uint64int8, int16, int32, int64float32, float64, complex64, complex128string, int, uintptr, byte, runeconst iota = 0, niltype error interface {}</code></pre>以及常用的內建函數:```func append(slice []Type, elems ...Type) []Typefunc copy(dst, src []Type) intfunc delete(m map[Type]Type1, key Type)// array, pointer, slice, string, channelfunc len(v Type) intfunc cap(v Type) int// slice, map, chanfunc make(t Type, size ...IntegerType) Typefunc new(Type) *Typefunc complex(r, i FloatType) ComplexTypefunc real(c ComplexType) FloatTypefunc imag(c ComplexType) FloatTypefunc close(c chan<- Type)func panic(v interface{})func recover() interface{}func print(args ...Type)func println(args ...Type)```以下是一個簡單的使用內建函數的程式:~~~package mainfunc main() {// make a slice, copy, lens := make([]string, 0)s = append(s, "Apple")s = append(s, "Orange", "Peach")println("len of s: ", len(s))for i, v := range s {println(i, v)}s2 := make([]string, 5)n := copy(s2, s)println("len of s2: ", len(s2))println("copied len: ", n)for i, v := range s2 {println(i, v)}// make a channel, close a channelc := make(chan string, 2)c <- "Dolphin"c <- "Shark"println(<-c)println(<-c)c <- "Seal"println(<-c)close(c)if _, ok := <-c; ok {println("Channel is open")} else {println("Channel is closed")}}~~~217 次點擊  ∙  1 贊  
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.