Skip to content

Commit 7958270

Browse files
committed
you're doing great
1 parent 9bab226 commit 7958270

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import "fmt"
4+
5+
type person struct {
6+
first string
7+
}
8+
9+
func (p person) speak() {
10+
fmt.Println(p.first)
11+
}
12+
13+
func main() {
14+
p1 := person{"McLeod"}
15+
p2 := person{"Bond"}
16+
p1.speak()
17+
p2.speak()
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
xi := []int{4,3,5,7,3,4,5}
7+
fmt.Println(xi)
8+
9+
for i, v := range xi {
10+
fmt.Println(i, v)
11+
}
12+
13+
m := map[string]int{"mcleod":42, "bond":32}
14+
fmt.Println(m)
15+
16+
for k, v := range m {
17+
fmt.Println(k, v)
18+
}
19+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import "fmt"
4+
5+
type human interface{
6+
speak()
7+
}
8+
9+
type person struct {
10+
first string
11+
}
12+
13+
func (p person) speak() {
14+
fmt.Println(p.first)
15+
}
16+
17+
type car struct {
18+
color string
19+
}
20+
21+
func (c car) speak() {
22+
fmt.Println("I am color:", c.color)
23+
}
24+
25+
func foo(h human) {
26+
fmt.Println(h)
27+
}
28+
29+
func main() {
30+
p1 := person{"McLeod"}
31+
p2 := person{"Bond"}
32+
c1 := car{"red"}
33+
foo(p1)
34+
foo(p2)
35+
foo(c1)
36+
}

0 commit comments

Comments
 (0)