Go语言

最近在学习并用go语言编程,发现go语言蛮好玩也挺有意思

 

Go语言”奇怪用法“实践总结

本文通过对A Tour of Go的实践,总结Go语言的基础用法。

 

1 Go语言”奇怪用法“有哪些?


1,go的变量声明顺序是:”先写变量名,再写类型名“,此与C/C++的语法孰优孰劣,可见下文解释:
http://blog.golang.org/gos-declaration-syntax

2,go是通过package来组织的(与python类似),只有package名为main的包可以包含main函数,一个可执行程序有且仅有一个main包,通过import关键字来导入其他非main包。

3,可见性规则。go语言中,使用大小写来决定该常量、变量、类型、接口、结构或函数是否可以被外部包含调用。根据约定,函数名首字母小写即为private,函数名首字母大写即为public。

4,go内置关键字(25个均为小写)。

5,函数不用先声明,即可使用。

6,在函数内部可以通过 := 隐士定义变量。(函数外必须显示使用var定义变量)

7,go程序使用UTF-8编码的纯Unicode文本编写。

8,使用big.Int的陷阱:
http://stackoverflow.com/questions/11270547/go-big-int-factorial-with-recursion

9,从技术层面讲,go语言的语句是以分号分隔的,但这些是由编译器自动添加的,不用手动输入,除非需要在同一行中写入多个语句。没有分号及只需少量的逗号和圆括号,使得go语言的程序更容易阅读。

10,go语言只有一个循环结构——for循环。

11,go里的自增运算符只有——“后++”

12,go语言中的slice用法类似python中数组,关于slice的详细用法可见:http://blog.golang.org/go-slices-usage-and-internals

13,函数也是一个值,使用匿名函数返回一个值。

14,函数闭包的使用,闭包是一个匿名函数值,会引用到其外部的变量。



2 代码实践


  1. /* gerryyang 
  2.  * 2013-11-23 
  3.  */  
  4.   
  5. package main  
  6.   
  7. import (  
  8.     "fmt"  
  9.     "math"  
  10.     "math/big"  
  11.     "math/cmplx"  
  12.     "math/rand"  
  13.     "net/http"  
  14.     "os"  
  15.     "runtime"  
  16.     "time"  
  17. )  
  18.   
  19. // Outside a function, every construct begins with a keyword (var, func, and so on) and the := construct is not available  
  20. // The var statement declares a list of variables; as in function argument lists, the type is last  
  21. var x, y, z int  
  22. var c, python, java bool  
  23.   
  24. // A var declaration can include initializers, one per variable  
  25. var x1, y1, z1 int = 1, 2, 3  
  26.   
  27. // If an initializer is present, the type can be omitted; the variable will take the type of the initializer  
  28. var c1, python1, java1 = truefalse"no!"  
  29.   
  30. // basic types  
  31. // bool  
  32. // string  
  33. // int int8 int16 int32 int64  
  34. // uint uint8 uint16 uint32 uint64 uintptr  
  35. // byte (alias for uint8)  
  36. // rune (alias for int32, represents a Unicode code point)  
  37. // float32 float64  
  38. // complex64 complex128  
  39. var (  
  40.     ToBe    bool       = false  
  41.     MaxInt  uint64     = 1<<64 - 1  
  42.     complex complex128 = cmplx.Sqrt(-5 + 12i)  
  43. )  
  44.   
  45. // Constants are declared like variables, but with the const keyword  
  46. const Pi = 3.14  
  47.   
  48. // Constants can be character, string, boolean, or numeric values  
  49. const World = "世界"  
  50.   
  51. // Numeric Constants  
  52. const (  
  53.     Big   = 1 << 100  
  54.     Small = Big >> 99 // 2  
  55. )  
  56.   
  57. type Vertex struct {  
  58.     X int  
  59.     Y int  
  60. }  
  61.   
  62. type Vertex2 struct {  
  63.     Lat, Long float64  
  64. }  
  65.   
  66. var m map[string]Vertex2  
  67.   
  68. // Map literals are like struct literals, but the keys are required  
  69. var m2 = map[string]Vertex2{  
  70.     "gerryyang": Vertex2{  
  71.         100, 200,  
  72.     },  
  73.     "wcdj": Vertex2{  
  74.         -300, 500,  
  75.     },  
  76. }  
  77.   
  78. // If the top-level type is just a type name, you can omit it from the elements of the literal  
  79. var m3 = map[string]Vertex2{  
  80.     "math":     {20, 40},  
  81.     "computer": {30, 50},  
  82. }  
  83.   
  84. type Vertex3 struct {  
  85.     X, Y float64  
  86. }  
  87.   
  88. type MyFloat float64  
  89.   
  90. type Abser interface {  
  91.     Abs() float64  
  92. }  
  93.   
  94.   
  95.   
  96. func main() {  
  97.     fmt.Println("Hello Golang, I'm gerryyang")  
  98.     fmt.Println("The time is", time.Now())  
  99.   
  100.     // To see a different number, seed the number generator; see rand.Seed  
  101.     fmt.Println("My favorite number is", rand.Intn(7))  
  102.     fmt.Printf("Now you have %g problesms\n", math.Nextafter(2, 3))  
  103.     // In Go, a name is exported if it begins with a capital letter  
  104.     fmt.Println(math.Pi)  
  105.   
  106.     // Notice that the type comes after the variable name  
  107.     fmt.Println(add(42, 13))  
  108.     fmt.Println(add2(42, 13))  
  109.   
  110.     // multiple results  
  111.     a, b := swap("gerry""yang")  
  112.     fmt.Println(a, b)  
  113.   
  114.     // named return  
  115.     fmt.Println(split(17))  
  116.     fmt.Println(split2(17))  
  117.   
  118.     // var used  
  119.     fmt.Println(x, y, z, c, python, java)  
  120.     fmt.Println(x1, y1, z1, c1, python1, java1)  
  121.   
  122.     // Inside a function, the := short assignment statement can be used in place of a var declaration with implicit type  
  123.     var x2, y2, z2 int = 1, 2, 3  
  124.     c2, python2, java2 := truefalse"yes!"  
  125.     fmt.Println(x2, y2, z2, c2, python2, java2)  
  126.   
  127.     // basic types  
  128.     const f = "%T(%v)\n"  
  129.     fmt.Printf(f, ToBe, ToBe)  
  130.     fmt.Printf(f, MaxInt, MaxInt)  
  131.     fmt.Printf(f, complex, complex)  
  132.   
  133.     // Constants cannot be declared using the := syntax  
  134.     const World2 = "和平"  
  135.     const Truth = true  
  136.     fmt.Println(Pi)  
  137.     fmt.Println("你好", World)  
  138.     fmt.Println("世界", World2)  
  139.     fmt.Println("Go rules?", Truth)  
  140.   
  141.     // Numeric Constants  
  142.     fmt.Println(needInt(Small))  
  143.     fmt.Println(needInt(Big))// error, constant 1267650600228229401496703205376 overflows int  
  144.     fmt.Println(needInt64(Big)) // error, same as above  
  145.     fmt.Println(needBigInt(big.NewInt(Big)))// error, 使用big.Int貌似入参最大类型只支持int64  
  146.     fmt.Println(needFloat(Small))  
  147.     fmt.Println(needFloat(Big))  
  148.   
  149.     // Go has only one looping construct, the for loop  
  150.     // The basic for loop looks as it does in C or Java, except that the ( ) are gone (they are not even optional) and the { } are required  
  151.     sum := 0  
  152.     for i := 0; i < 10; i++ {  
  153.         sum += i  
  154.     }  
  155.     fmt.Println(sum)  
  156.   
  157.     // As in C or Java, you can leave the pre and post statements empty  
  158.     // At that point you can drop the semicolons: C's while is spelled for in Go  
  159.     sum1 := 1  
  160.     for sum1 < 1000 {  
  161.         sum1 += sum1  
  162.     }  
  163.     fmt.Println(sum1)  
  164.   
  165.     // If you omit the loop condition it loops forever, so an infinite loop is compactly expressed  
  166.     ivar := 1  
  167.     for {  
  168.         if ivar++; ivar > 1000 {  
  169.             fmt.Println("leave out an infinite loop")  
  170.             break  
  171.         }  
  172.     }  
  173.   
  174.     // The if statement looks as it does in C or Java, except that the ( ) are gone and the { } are required  
  175.     fmt.Println(sqrt(2), sqrt(-4))  
  176.   
  177.     // Like for, the if statement can start with a short statement to execute before the condition  
  178.     fmt.Println(pow(3, 2, 10), pow(3, 3, 20))  
  179.   
  180.     // If and else  
  181.     fmt.Println(pow2(3, 2, 10), pow2(3, 3, 20))  
  182.   
  183.       
  184.   
  185.     // A struct is a collection of fields  
  186.     fmt.Println(Vertex{1, 2})  
  187.   
  188.     // Struct fields are accessed using a dot  
  189.     v := Vertex{1, 2}  
  190.     v.X = 4  
  191.     fmt.Println(v)  
  192.   
  193.     // Go has pointers, but no pointer arithmetic  
  194.     // Struct fields can be accessed through a struct pointer. The indirection through the pointer is transparent  
  195.     p := Vertex{1, 2}  
  196.     q := &p  
  197.     q.X = 1e9  
  198.     fmt.Println(p)  
  199.   
  200.     // struct literals  
  201.     // A struct literal denotes a newly allocated struct value by listing the values of its fields  
  202.     p = Vertex{1, 2}  // has type Vertex  
  203.     q = &Vertex{1, 2} // has type * Vertex  
  204.     r := Vertex{X: 1} // Y:0 is implicit  
  205.     s := Vertex{}     // X:0 and Y:0  
  206.     fmt.Println(p, q, r, s)  
  207.   
  208.     // The expression new(T) allocates a zeroed T value and returns a pointer to it  
  209.     // var t *T = new(T) or t := new(T)  
  210.     pv := new(Vertex)  
  211.     fmt.Println(pv)  
  212.     pv.X, pv.Y = 11, 9  
  213.     fmt.Println(pv)  
  214.   
  215.     // A slice points to an array of values and also includes a length  
  216.     // []T is a slice with elements of type T  
  217.     as := []int{2, 3, 5, 7, 11, 13}  
  218.     fmt.Println("as ==", as)  
  219.     for i := 0; i < len(as); i++ {  
  220.         fmt.Printf("as[%d] == %d\n", i, as[i])  
  221.     }  
  222.   
  223.     // Slices can be re-sliced, creating a new slice value that points to the same array  
  224.     // The expression: s[lo:hi]  
  225.     // evaluates to a slice of the elements from lo through hi-1, inclusive  
  226.     fmt.Println("as[1:4] ==", as[1:4])  
  227.     // missing low index implies 0  
  228.     fmt.Println("as[:3] ==", as[:3])  
  229.     // missing high index implies len(s)  
  230.     fmt.Println("as[4:] ==", as[4:])  
  231.   
  232.     // Slices are created with the make function. It works by allocating a zeroed array and returning a slice that refers to that array  
  233.     // a := make([]int, 5), note, len(a) = 5  
  234.     // To specify a capacity, pass a third argument to make  
  235.     // b := make([]int, 0 , 5), note, len(b) = 0, cap(b) = 5  
  236.     // b = b[:cap(b)], note, len(b) = 5, cap(b) = 5  
  237.     // b = b[1:], note, len(b) = 4, cap(b) = 4  
  238.     s1 := make([]int, 5)  
  239.     printSlice("s1", s1)  
  240.     s2 := make([]int, 0, 5)  
  241.     printSlice("s2", s2)  
  242.     s3 := s2[:2]  
  243.     printSlice("s3", s3)  
  244.     s4 := s3[2:5]  
  245.     printSlice("s4", s4)  
  246.   
  247.     // The zero value of a slice is nil  
  248.     // A nil slice has a length and capacity of 0  
  249.     var s5 []int  
  250.     fmt.Println(s5, len(s5), cap(s5))  
  251.     if s5 == nil {  
  252.         fmt.Println("slice is nil")  
  253.     }  
  254.   
  255.     // The range form of the for loop iterates over a slice or map  
  256.     var s6 = []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}  
  257.     for i, v := range s6 {  
  258.         fmt.Printf("2**%d = %d\n", i, v)  
  259.     }  
  260.   
  261.     // If you only want the index, drop the ", value" entirely  
  262.     for i := range s6 {  
  263.         s6[i] = 1 << uint(i)  
  264.     }  
  265.     // You can skip the index or value by assigning to _  
  266.     for _, value := range s6 {  
  267.         fmt.Printf("%d\n", value)  
  268.     }  
  269.   
  270.     // A map maps keys to values  
  271.     // Maps must be created with make (not new) before use; the nil map is empty and cannot be assigned to  
  272.     m = make(map[string]Vertex2)  
  273.     m["Bell Labs"] = Vertex2{  
  274.         40.68433, -74.39967,  
  275.     }  
  276.     fmt.Println(m["Bell Labs"])  
  277.   
  278.     // Map literals are like struct literals, but the keys are required  
  279.     fmt.Println(m2)  
  280.   
  281.     // If the top-level type is just a type name, you can omit it from the elements of the literal  
  282.     fmt.Println(m3)  
  283.   
  284.     // map  
  285.     // insert, update, retrieve, delete, test  
  286.     m4 := make(map[string]int)  
  287.     m4["date"] = 20131129  
  288.     fmt.Println("The value:", m4["date"])  
  289.     m4["date"] = m4["date"] + 1  
  290.     fmt.Println("The value:", m4["date"])  
  291.     date, ok := m4["date"]  
  292.     fmt.Println("The value:", date, "Present?", ok)  
  293.   
  294.     delete(m4, "date")  
  295.     fmt.Println("The value:", m4["date"])  
  296.     date2, ok := m4["date"]  
  297.     fmt.Println("The value:", date2, "Present?", ok)  
  298.   
  299.     // Function values  
  300.     // Functions are values too  
  301.     hypot := func(x, y float64) float64 {  
  302.         return math.Sqrt(x*x + y*y)  
  303.     }  
  304.     fmt.Println(hypot(3, 4))  
  305.   
  306.     // Function closures  
  307.     // For example, the adder function returns a closure. Each closure is bound to its own sum variable  
  308.     pos, neg := adder(), adder()  
  309.     for i := 0; i < 10; i++ {  
  310.         fmt.Println(pos(i), neg(-2*i))  
  311.     }  
  312.   
  313.     // fibonacci  
  314.     fib := fibonacci()  
  315.     for i := 0; i < 10; i++ {  
  316.         fmt.Println(fib())  
  317.     }  
  318.   
  319.     // switch  
  320.     // A case body breaks automatically, unless it ends with a fallthrough statement  
  321.     switch os := runtime.GOOS; os {  
  322.     case "darwin":  
  323.         fmt.Println("OS X")  
  324.     case "linux":  
  325.         fmt.Println("Linux")  
  326.     default:  
  327.         // freebsd, openbsd  
  328.         // plan9, windows...  
  329.         fmt.Printf("%s", os)  
  330.     }  
  331.   
  332.     // Switch cases evaluate cases from top to bottom, stopping when a case succeeds  
  333.     // Note: Time in the Go playground always appears to start at 2009-11-10 23:00:00 UTC  
  334.     fmt.Println("When's Saturday?")  
  335.     today := time.Now().Weekday()  
  336.     switch time.Saturday {  
  337.     case today + 0:  
  338.         fmt.Println("Today")  
  339.     case today + 1:  
  340.         fmt.Println("Tomorrow")  
  341.     case today + 2:  
  342.         fmt.Println("In two days")  
  343.     case today + 3:  
  344.         fmt.Println("In three days")  
  345.     default:  
  346.         fmt.Println("Too far away")  
  347.     }  
  348.   
  349.     // Switch without a condition is the same as switch true  
  350.     // This construct can be a clean way to write long if-then-else chains  
  351.     t_now := time.Now()  
  352.     switch {  
  353.     case t_now.Hour() < 12:  
  354.         fmt.Println("Good morning!")  
  355.     case t_now.Hour() < 17:  
  356.         fmt.Println("Good afternoon")  
  357.     default:  
  358.         fmt.Println("Good evening")  
  359.     }  
  360.   
  361.     // Go does not have classes. However, you can define methods on struct types  
  362.     v3 := &Vertex3{3, 4}  
  363.     fmt.Println(v3.Abs())  
  364.   
  365.     // In fact, you can define a method on any type you define in your package, not just structs  
  366.     // You cannot define a method on a type from another package, or on a basic type  
  367.     f1 := MyFloat(-math.Sqrt2)  
  368.     fmt.Println(f1.Abs())  
  369.   
  370.     // Methods with pointer receivers  
  371.     // Methods can be associated with a named type or a pointer to a named type  
  372.     // We just saw two Abs methods. One on the *Vertex pointer type and the other on the MyFloat value type  
  373.     // There are two reasons to use a pointer receiver. First, to avoid copying the value on each method call (more efficient if the value type is a large struct). Second, so that the method can modify the value that its receiver points to  
  374.     v3 = &Vertex3{3, 4}  
  375.     v3.Scale(5)  
  376.     fmt.Println(v3, v3.Abs())  
  377.   
  378.     // An interface type is defined by a set of methods  
  379.     // A value of interface type can hold any value that implements those methods  
  380.     var a_interface Abser  
  381.     v4 := Vertex3{3, 4}  
  382.     a_interface = f1  // a MyFloat implements Abser  
  383.     a_interface = &v4 // a *Vertex3 implements Abser  
  384.     //a_interface = v4  // a Vertex3, does Not, error!  
  385.     fmt.Println(a_interface.Abs())  
  386.   
  387.     // Interfaces are satisfied implicitly  
  388.     var w Writer  
  389.     // os.Stdout implements Writer  
  390.     w = os.Stdout  
  391.     fmt.Fprintf(w, "hello, writer\n")  
  392.   
  393.     // An error is anything that can describe itself as an error string. The idea is captured by the predefined, built-in interface type, error, with its single method, Error, returning a string: type error interface { Error() string }  
  394.     if err := run(); err != nil {  
  395.         fmt.Println(err)  
  396.     }  
  397.   
  398.     // Web servers  
  399.     //var h Hello  
  400.     //http.ListenAndServe("localhost:4000", h)  
  401.   
  402. }  
  403.   
  404. /  
  405.   
  406. // func can be used before declare  
  407. func add(x int, y intint {  
  408.     return x + y  
  409. }  
  410.   
  411. // When two or more consecutive named function parameters share a type, you can omit the type from all but the last  
  412. func add2(x, y intint {  
  413.     return x + y  
  414. }  
  415.   
  416. // multiple results, a function can return any number of results  
  417. func swap(x, y string) (string, string) {  
  418.     return y, x  
  419. }  
  420.   
  421. // In Go, functions can return multiple "result parameters", not just a single value. They can be named and act just like variables  
  422. func split(sum int) (x, y int) {  
  423.     x = sum * 4 / 9  
  424.     y = sum - x  
  425.     return y, x  
  426. }  
  427.   
  428. // In Go, functions can return multiple "result parameters", not just a single value. They can be named and act just like variables  
  429. func split2(sum int) (x, y int) {  
  430.     x = sum * 4 / 9  
  431.     y = sum - x  
  432.   
  433.     // If the result parameters are named, a return statement without arguments returns the current values of the results  
  434.     return  
  435. }  
  436.   
  437. func needInt(x intint       { return x*10 + 1 }  
  438. func needInt64(x int64) int64 { return x*10 + 1 }  
  439. func needBigInt(x *big.Int) (result *big.Int) {  
  440.     result = new(big.Int)  
  441.     result.Set(x)  
  442.     result.Mul(result, big.NewInt(10))  
  443.     return  
  444. }  
  445. func needFloat(x float64) float64 {  
  446.     return x * 0.1  
  447. }  
  448.   
  449. func sqrt(x float64) string {  
  450.     if x < 0 {  
  451.         return sqrt(-x) + "i"  
  452.     }  
  453.     return fmt.Sprint(math.Sqrt(x))  
  454. }  
  455.   
  456. // Variables declared by the statement are only in scope until the end of the if  
  457. func pow(x, n, lim float64) float64 {  
  458.     if v := math.Pow(x, n); v < lim {  
  459.         return v  
  460.     }  
  461.     return lim  
  462. }  
  463.   
  464. // Variables declared inside an if short statement are also available inside any of the else blocks  
  465. func pow2(x, n, lim float64) float64 {  
  466.     if v := math.Pow(x, n); v < lim {  
  467.         return v  
  468.     } else {  
  469.         fmt.Printf("%g >= %g\n", v, lim)  
  470.     }  
  471.     // can't use v here, though  
  472.     return lim  
  473. }  
  474.   
  475. func printSlice(s string, x []int) {  
  476.     fmt.Printf("%s len = %d cap = %d %v\n", s, len(x), cap(x), x)  
  477. }  
  478.   
  479. // Go functions may be closures. A closure is a function value that references variables from outside its body. The function may access and assign to the referenced variables; in this sense the function is "bound" to the variables  
  480. func adder() func(intint {  
  481.     sum := 0  
  482.     return func(x intint {  
  483.         sum += x  
  484.         return sum  
  485.     }  
  486. }  
  487.   
  488. // fibonacci is a function that returns  
  489. // a function that returns an int.  
  490. func fibonacci() func() int {  
  491.     p := 0  
  492.     q := 1  
  493.     s := 0  
  494.     return func() int {  
  495.         s = p + q  
  496.         p = q  
  497.         q = s  
  498.         return s  
  499.     }  
  500. }  
  501.   
  502. // The method receiver appears in its own argument list between the func keyword and the method name  
  503. func (v *Vertex3) Abs() float64 {  
  504.     return math.Sqrt(v.X*v.X + v.Y*v.Y)  
  505. }  
  506.   
  507. func (f MyFloat) Abs() float64 {  
  508.     if f < 0 {  
  509.         fmt.Println("f < 0 here")  
  510.         return float64(-f)  
  511.     }  
  512.     return float64(f)  
  513. }  
  514.   
  515. // Methods with pointer receivers  
  516. func (v *Vertex3) Scale(f float64) {  
  517.     v.X = v.X * f  
  518.     v.Y = v.Y * f  
  519. }  
  520.   
  521. // Interfaces are satisfied implicitly  
  522. type Reader interface {  
  523.     Read(b []byte) (n int, err error)  
  524. }  
  525. type Writer interface {  
  526.     Write(b []byte) (n int, err error)  
  527. }  
  528. type ReadWriter interface {  
  529.     Reader  
  530.     Writer  
  531. }  
  532.   
  533. // error control  
  534. type MyError struct {  
  535.     When time.Time  
  536.     What string  
  537. }  
  538.   
  539. func (e *MyError) Error() string {  
  540.     return fmt.Sprintf("at %v, %s", e.When, e.What)  
  541. }  
  542. func run() error {  
  543.     return &MyError{  
  544.         time.Now(),  
  545.         "it didn't work",  
  546.     }  
  547. }  
  548.   
  549. // Web servers  
  550. type Hello struct{}  
  551.   
  552. func (h Hello) ServeHTTP(  
  553.     w http.ResponseWriter,  
  554.     r *http.Request) {  
  555.     fmt.Fprint(w, "gerryyang")  
  556. }  
  557.   
  558.   
  559. /* 
  560. output: 
  561.  
  562. Hello Golang, I'm gerryyang 
  563. The time is 2013-12-04 22:52:01.336562598 +0800 HKT 
  564. My favorite number is 6 
  565. Now you have 2.0000000000000004 problesms 
  566. 3.141592653589793 
  567. 55 
  568. 55 
  569. yang gerry 
  570. 10 7 
  571. 7 10 
  572. 0 0 0 false false false 
  573. 1 2 3 true false no! 
  574. 1 2 3 true false yes! 
  575. bool(false) 
  576. uint64(18446744073709551615) 
  577. complex128((2+3i)) 
  578. 3.14 
  579. 你好 世界 
  580. 世界 和平 
  581. Go rules? true 
  582. 21 
  583. 0.2 
  584. 1.2676506002282295e+29 
  585. 45 
  586. 1024 
  587. leave out an infinite loop 
  588. 1.4142135623730951 2i 
  589. 9 20 
  590. 27 >= 20 
  591. 9 20 
  592. {1 2} 
  593. {4 2} 
  594. {1000000000 2} 
  595. {1 2} &{1 2} {1 0} {0 0} 
  596. &{0 0} 
  597. &{11 9} 
  598. as == [2 3 5 7 11 13] 
  599. as[0] == 2 
  600. as[1] == 3 
  601. as[2] == 5 
  602. as[3] == 7 
  603. as[4] == 11 
  604. as[5] == 13 
  605. as[1:4] == [3 5 7] 
  606. as[:3] == [2 3 5] 
  607. as[4:] == [11 13] 
  608. s1 len = 5 cap = 5 [0 0 0 0 0] 
  609. s2 len = 0 cap = 5 [] 
  610. s3 len = 2 cap = 5 [0 0] 
  611. s4 len = 3 cap = 3 [0 0 0] 
  612. [] 0 0 
  613. slice is nil 
  614. 2**0 = 1 
  615. 2**1 = 2 
  616. 2**2 = 4 
  617. 2**3 = 8 
  618. 2**4 = 16 
  619. 2**5 = 32 
  620. 2**6 = 64 
  621. 2**7 = 128 
  622. 2**8 = 256 
  623. 2**9 = 512 
  624. 2**10 = 1024 
  625. 1 
  626. 2 
  627. 4 
  628. 8 
  629. 16 
  630. 32 
  631. 64 
  632. 128 
  633. 256 
  634. 512 
  635. 1024 
  636. {40.68433 -74.39967} 
  637. map[gerryyang:{100 200} wcdj:{-300 500}] 
  638. map[math:{20 40} computer:{30 50}] 
  639. The value: 20131129 
  640. The value: 20131130 
  641. The value: 20131130 Present? true 
  642. The value: 0 
  643. The value: 0 Present? false 
  644. 5 
  645. 0 0 
  646. 1 -2 
  647. 3 -6 
  648. 6 -12 
  649. 10 -20 
  650. 15 -30 
  651. 21 -42 
  652. 28 -56 
  653. 36 -72 
  654. 45 -90 
  655. 1 
  656. 2 
  657. 3 
  658. 5 
  659. 8 
  660. 13 
  661. 21 
  662. 34 
  663. 55 
  664. 89 
  665. OS X 
  666. When's Saturday? 
  667. In three days 
  668. Good evening 
  669. 5 
  670. f < 0 here 
  671. 1.4142135623730951 
  672. &{15 20} 25 
  673. 5 
  674. hello, writer 
  675. at 2013-12-04 22:52:01.337206342 +0800 HKT, it didn't work 
  676.  
  677.  
  678.  
  679. */  
原文出自:http://blog.csdn.net/delphiwcdj/article/details/16903649

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值