go語言基礎

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

go語言是自己剛接觸的。記一下經常用到的東西

1、建立一個新項目時候 ,在該目錄下(D:\devtools\go\src),建立hello.go 檔案。在go語言中檔案以 .go命名。

2、運行代碼結果時,(本人用的是sublime  text3)用Ctrl+B快速鍵 ,然後輸入  go  run  hello.go  斷行符號,得到運行結果。

3、go語言基本文法

每個go程式都是由包組成的。

程式啟動並執行入口是包 main       

package main

這個程式使用並匯入包fmt“ 和 “math/rand“ 

import (    "fmt"    "math/rand" )
func main() {    fmt.Printf("Now you have %g problems.", math.Sqrt(7))   //這裡用math的話匯入包中必須有math}匯入包之間的關係:import "fmt"  是最基本的匯入包import ("fmt"  "math/rand")  
func main() {    fmt.Println("My favorite number is", rand.Intn(10))}import ("fmt"  "math")
func main() {    fmt.Printf("Now you have %g problems.", math.Sqrt(7))}

匯出名稱

在 Go 中,首字母大寫的名稱是被匯出的。(本人理解匯出名稱是fmt.Printf()中的值)




 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.