Advertisement
Koepnick

variables

Jan 15th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.59 KB | None | 0 0
  1. // Empty
  2. // Default values for numerics is 0, for strings is "" and for bool is false
  3. var i int
  4.  
  5. // Long init and/or outside the scope of a function
  6. // Type is inferred from the assignment
  7. var i = 0
  8.  
  9. // Shortcut
  10. // Type is inferred from the assignment
  11. i := 0
  12.  
  13. // Multiple assignments
  14. a, b, c := "string", 0, 3.5
  15.  
  16. // Block initialization outside of a function
  17. var (
  18.     a int
  19.     b string
  20.     c float64
  21.     d float32
  22. )
  23.  
  24. // Constants
  25. const Pi = 3.14
  26.  
  27. const (
  28.    // Pi is 3.14 and this comment is required
  29.     Pi = 3.14
  30.    // Tau is half of pi, also this comment is required
  31.     Tau = Pi / 2
  32. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement