Skip to content

Instantly share code, notes, and snippets.

a = [1, 2, 3, 4, 5]
# slice [start:end]
print(a[1:3]) # [2 3]
print(a[-3: -1]) # [3, 4]
# slice [start:end:step]
print(a[::2]) # [1 3 5]
print(a[::-1]) # [5 4 3 2 1]
a = [1, 2, 3, 4, 5]
print(a[0], a[-1]) # 1 5
# 1
a, b, c = 1, 2, 3
d = a, b, c
print(d, type(d)) # (1, 2, 3) tuple
# 2
a, b, c = (2 * i + 1 for i in range(3))
d = a, b, c
print(d) # (1, 3, 5)
package main
import "fmt"
// define interfaces
type Vehicle interface {
Move() string
}
// define structs and implement Vehicle interface
@bolerap
bolerap / golang-interface.go
Last active November 2, 2016 05:55
Golang interface
func doSomething(v interface{}) {
// v argument has type interface{} not any type
}
@bolerap
bolerap / serve.go
Created September 27, 2016 07:22 — forked from paulmach/serve.go
Simple Static File Server in Go
/*
Serve is a very simple static file server in go
Usage:
-p="8100": port to serve on
-d=".": the directory of static files to host
Navigating to http://localhost:8100 will display the index.html or directory
listing file.
*/
package main