[GPWG] Unit 0. Getting started

aside section._1OhGeD · · 2007 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

get programming with go

https://play.golang.org/

https://golang.org/ref/spec

Unit 0 Getting started

lesson 1 get ready, get set, go

  • With the Go Playground you can start using Go without installing anything.
  • Every Go program is made up of functions contained in packages.
  • To print text on the screen, use the fmt package provided by the standard library.
  • Punctuation is just as important in programming languages as it is in natural languages.
  • You used 3 of the 25 Go keywords: package, import, and func

total 25 key words

break        default      func         interface    select
case         defer        go           map          struct
chan         else         goto         package      switch
const        fallthrough  if           range        type
continue     for          import       return       var

Unit 1 Imperative programming

Travel to Mars.

lesson 2 a glorified calculator

package main

import "fmt"

func main() {
    fmt.Print("My weight on the surface of Mars is ")
    fmt.Print(149.0 * 0.3783) // always 37.83%
    fmt.Print(" lbs, and I would be ")
    fmt.Print(41 * 365 / 687)
    fmt.Print(" years old.")

    fmt.Println()
    fmt.Println("My weight on the surface of Mars is", 70*0.3783, " KG, and I would be ", 36*365/687, " years old.")

    //  %v for the value of the expression. https://golang.org/pkg/fmt/
    fmt.Printf("My weight on the surface of Mars is %v KG, and I would be %v  years old.\n", 70*0.3783, 36*365/687)

    //align text.
    // positive value pads with spaces to the left,
    // negtive number pads with spaces to the right.
    fmt.Printf("%-15v $%4v\n", "SpaceX", 94)
    fmt.Printf("%-15v $%4v\n", "Virgin Galactic", 100)

    const lightSpeed = 299792 // km/s
    var distance = 56000000   //km
    fmt.Println(distance/lightSpeed, " seconds")
    distance = 401000000
    fmt.Println(distance/lightSpeed, " seconds")
}



有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:aside section._1OhGeD

查看原文:[GPWG] Unit 0. Getting started

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2007 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传