This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
var marks = map[string]int{} | |
marks["sakeef"] = 95 | |
marks["oishie"] = 82 | |
marks["robin"] = 61 | |
marks["mim"] = 43 | |
println(marks["sakeef"], marks["oishie"], marks["robin"], marks["mim"]) | |
// 95 82 61 43 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
var a = [4]int{1, 2, 3, 4} | |
var s = a[0:3] // s contains {1, 2, 3} | |
s[0] = 5 | |
println(s[0], a[0]) // 5 5 | |
s = append(s, 6) | |
println(s[3], a[3]) // 6 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
var s = []int{1, 2, 3, 4} | |
println(s[0], s[1], s[2], s[3]) // 1 2 3 4 | |
s = append(s, 13) | |
println(s[4], len(s), cap(s)) // 13 5 8 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
var a = [6]int {1, 2, 3, 4, 5, 6} | |
var sl = a[2:5] | |
println(sl[0]) // 3 | |
sl[0] = 13 | |
println(a[2]) // 13 | |
var s2 = a[1:3] | |
s2[1] = 23 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
var a [2]string | |
a[0] = "Hello" | |
a[1] = "World" | |
println(a[0], a[1]) // Hello World | |
primes := [6]int{2, 3, 5, 7, 11, 13} | |
println(primes[0], primes[1], primes[2], primes[3], primes[4], primes[5]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
const World = "Hello" | |
World = "Hola" // cannot assign to World | |
println(World) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
var i int | |
var f float64 | |
var b bool | |
var s string | |
println(i, ", ", f, ", ", b, ", ", s, ". ") // 0 , +0.000000e+000 , false , . | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
var i, j = 1, 2.3 | |
println(i + j) | |
// invalid operation: i + j (mismatched types int and float64) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
i := 5 | |
var j float32 = i // cannot use i (type int) as type float32 in assignment | |
println(j) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
var i, j = 1, 2 | |
k := 3 | |
c, python, java := true, false, "no!" | |
println(i, j, k, c, python, java) // 1 2 3 true false no! | |
} |