Slide 1

Slide 1 text

(Pݚमୈظ %": :VUBLB,BUP 
 3% %&4".*4 %&4".*4ࣾ಺ݚम

Slide 2

Slide 2 text

˞ લճͷ13ͷ 
 ղઆλΠϜ

Slide 3

Slide 3 text

ݚमܭը ճ ೔࣍ ༧ఆ λΠτϧ ୈճ Ր (Pͷجຊ ୈճ Ր ؀ڥߏஙͱ(JU (JU)VCͷجຊ ୈճ Ր جຊߏจ ୈճ Ր ߏ଄ମɺεϥΠεɺϚοϓ ୈճ Ր ඪ४ϥΠϒϥϦ͸΍Ί͙Γ ୈճ Ր ϞδϡʔϧγεςϜͱ֎෦ϥΠϒϥϦ ୈճ Ր )FSPLV(Pೖ໳ ୈճ Ր "84-BNCEB(Pೖ໳ ୈճ Ր ฒߦॲཧϓϩάϥϛϯά ୈճ Ր ୯ମςετٕ๏ ୈճ Ր σʔλϕʔεΞΫηε ୈճ Ր 'ZOFʹΑΔ(6*ΞϓϦέʔγϣϯ։ൃ ୈճ Ր ࣾ಺(PϓϩδΣΫτͷίʔυղઆ

Slide 4

Slide 4 text

ຊ೔ͷΰʔϧ w 🚩ΰʔϧ w (Pͷ༷ʑͳσʔλߏ଄Λशಘ͢Δ w (PͷΦϒδΣΫτࢦ޲ʹ৮ΕΔ w ❌ΰʔϧͰ͸ͳ͍ w (Pͷશͯͷߏจ΍σʔλߏ଄Λशಘ͢Δ

Slide 5

Slide 5 text

഑ྻͱεϥΠε

Slide 6

Slide 6 text

഑ྻɾεϥΠε package mai n import "fmt " func main() { intArray := [3]int{1, 2, 3} // ഑ྻ (ݻఆ௕ ) intSlice := []int{1, 2, 3} // εϥΠε (Մม௕ ) intSlice = append(intSlice, 4) // εϥΠεʹ஋Λ௥Ճ fmt.Println(intArray, len(intArray)) // [1 2 3] 3 fmt.Println(intSlice, len(intSlice)) // [1 2 3 4] 4 } ഑ྻ͸ݻఆ௕ɺεϥΠε͸Մม௕
 ഑ྻ͸Ίͬͨʹ࢖Θͳ͍

Slide 7

Slide 7 text

εϥΠεͷߏ଄ EBUB MFO DBQ +BOVBSZ l'FCSVBSZ l.BSDI l"QSJM l.BZ l+VOF l+VMZ l"VHVTU l4FQUFNCFS l0DUPCFS l/PWFNCFS l%FDFNCFS EBUB MFO DBQ Q2 := months[4:7] summer := months[6:9] MFO DBQ MFO DBQ ڭՊॻ1ਤ

Slide 8

Slide 8 text

NBLF package mai n import "fmt " func main() { s1 := make([]int, 0 ) fmt.Println(s1, cap(s1)) // [] 0 s2 := make([]int, 0, 7 ) fmt.Println(s2, cap(s2)) // [] 7 } make() Ͱॳظͷ௕͞ͱ༰ྔΛࢦఆͯ͠εϥΠεΛ࡞੒Ͱ͖Δ
 ༧Ί࠷େ༰ྔ͕෼͔͍ͬͯΔ৔߹ʹޮ཰Α͘࡞੒͢ΔͨΊʹ࢖͏͜ͱ͕͋Δ

Slide 9

Slide 9 text

ϑΟϧλϦϯά package mai n import "fmt " func main() { stations := []string{"וా", "໼ޱ౉", "෢ଂ৽ా", "Լؙࢠ", "ӏͷ໦", "প෦", "ଟຎ઒" } var sanmoji []string // جఈ഑ྻΛ࠶ར༻͢Δ৔߹: var sanmoji = stations[:0 ] for _, s := range stations { if len([]rune(s)) == 3 { sanmoji = append(sanmoji, s ) } } fmt.Println(sanmoji) // [໼ޱ౉ Լؙࢠ ӏͷ໦ ଟຎ઒ ] } filter() ͱ͔͸ͳ͍ͷͰɺ۪௚ʹ for Λճ͢

Slide 10

Slide 10 text

൓స package mai n import "fmt " func main() { stations := []string{"וా", "໼ޱ౉", "෢ଂ৽ా", "Լؙࢠ", "ӏͷ໦", "প෦", "ଟຎ઒" } for i, j := 0, len(stations)-1; i < j; i, j = i+1, j-1 { stations[i], stations[j] = stations[j], stations[i ] } fmt.Println(stations) // [ଟຎ઒ প෦ ӏͷ໦... ] } reverse() ͱ͔͸ͳ͍ͷͰɺ۪௚ʹ for Λճ͢

Slide 11

Slide 11 text

ෳ੡ package mai n import "fmt " func main() { stations := []string{"וా", "໼ޱ౉", "෢ଂ৽ా", "Լؙࢠ", "ӏͷ໦", "প෦", "ଟຎ઒" } stations2 := make([]string, len(stations) ) copy(stations2, stations ) fmt.Println(stations) // [וా ໼ޱ౉ ෢ଂ৽ా... ] } ෳ੡͸ copy() Λ࢖͏

Slide 12

Slide 12 text

ؒΛൈ͘ package mai n import "fmt " func main() { stations := []string{"וా", "໼ޱ౉", "෢ଂ৽ా", "Լؙࢠ", "ӏͷ໦", "প෦", "ଟຎ઒" } stations = append(stations[:4], stations[5:]...) // 0ʙ3 + 5ʙ 6 fmt.Println(stations) // [וా ໼ޱ౉ ෢ଂ৽ా Լؙࢠ প෦ ଟຎ઒ ] } εϥΠεԋࢉࢠͱ append() Ͱࣗ༝ࣗࡏʂ

Slide 13

Slide 13 text

Ϛοϓ

Slide 14

Slide 14 text

Ϛοϓ package mai n import "fmt " func main() { ages := map[string]int { "alice": 31 , "charlie": 34 , } fmt.Println(ages["alice"]) // 3 1 } make() package mai n import "fmt " func main() { ages := make(map[string]int ) ages["alice"] = 3 1 ages["charlie"] = 3 4 fmt.Println(ages["alice"]) // 3 1 } ϚοϓϦςϥϧ

Slide 15

Slide 15 text

Ϛοϓͷ୳ࡧ package mai n import "fmt " func main() { ages := map[string]int { "alice": 31 , "charlie": 34 , } for k, v := range ages { if v > 33 { fmt.Println(k, v) // charlie 3 4 } } } for + range ʹ͔͚ΔͱΩʔɾ஋Λर͏͜ͱ͕Ͱ͖Δ
 औΓग़͞ΕΔॱং͸ཪଆͰγϟοϑϧ͞Ε͍ͯΔ

Slide 16

Slide 16 text

ηοτ package mai n import "fmt " func main() { set := map[string]bool{"A": true, "B": true, "C": true } for k := range set { fmt.Println(k ) } } ηοτΛදݱ͍ͨ͠৔߹͸ɺΩʔ͚ͩ࢖͏Ϛοϓͱͯ͠࢖͏

Slide 17

Slide 17 text

ߏ଄ମ

Slide 18

Slide 18 text

ߏ଄ମ package mai n import "fmt " type Employee struct { ID in t Name strin g } func main() { var kato Employe e fmt.Println(kato.ID, kato.Name) // 0 kato = Employee{ID: 82, Name: "Ճ౻" } fmt.Println(kato.ID, kato.Name) // 82 Ճ౻ } struct{} Ͱߏ଄ମΛఆٛͰ͖Δ
 ߏ଄ମϦςϥϧͰ؆୯ʹ૊ΈཱΔ͜ͱ͕Ͱ͖Δ

Slide 19

Slide 19 text

ߏ଄ମͷຒΊࠐΈ package mai n import "fmt " type Point struct { X, Y in t } type Circle struct { Center Poin t Radius in t } func main() { c := Circle { Center: Point{X: 10, Y: 15} , Radius: 5 , } fmt.Println(c.Center.X) // 1 0 } package mai n import "fmt " type Point struct { X, Y in t } type Circle struct { Poin t Radius in t } func main() { c := Circle { Point: Point{X: 10, Y: 15} , Radius: 5 , } fmt.Println(c.X) // 1 0 } ຒΊࠐΈ ຒΊࠐΈ ແ໊ϑΟʔϧυ ஫໨ʂ

Slide 20

Slide 20 text

ΦϒδΣΫτࢦ޲

Slide 21

Slide 21 text

ϝιου package mai n import "fmt " type Employee struct { ID in t Name strin g AnnualSalary in t } func (e Employee) MonthlySalary() int { return e.AnnualSalary / 1 2 } func main() { kato := Employee{ID: 82, Name: "Ճ౻", AnnualSalary: 3000000 } fmt.Println(kato.MonthlySalary() ) } ؔ਺໊ͷલʹϨγʔόʔͱܕΛॻ͘ͱϝιουʹͳΔ Ϩγʔόʔ

Slide 22

Slide 22 text

ϝιου package mai n type Employee struct { ID in t Name strin g Projects []strin g } func (e *Employee) Assign(pj string) { e.Projects = append(e.Projects, pj ) } func main() { kato := Employee{ID: 82, Name: "Ճ౻", Projects: []string{"։ൃ"} } kato.Assign("ӡ༻") } ϙΠϯλϨγʔόʔ ม਺ͷมߋΛߦ͏ϝιου͸ϙΠϯλϨγʔόʔʹ͢Δඞཁ͕͋Δ

Slide 23

Slide 23 text

ϝιου package mai n import "fmt " type User struct { ID int6 4 password strin g } func (u User) Authenticate(password string) bool { return u.password == passwor d } func (u User) csv() string { return fmt.Sprintf("id,password\n%d,*****\n", u.ID ) } খจࣈͰ࢝·ΔϑΟʔϧυ ֎ͷύοέʔδ͔ΒӅ͍ͨ͠ϑΟʔϧυ΍ϝιου͸খจࣈ͔Β࢝ΊΔ খจࣈͰ࢝·Δϝιου

Slide 24

Slide 24 text

ΠϯλϑΣʔε package mai n import "fmt " type Caller interface { Call() strin g } type Cattle struct { ID int6 4 } func (c Cattle) Call() string { return "moo " } func main() { var c Calle r c = Cattle{ID: 123} fmt.Println(c.Call()) // "moo " } $BMMFSܕͷม਺ʹ 
 $BUUMFΛ୅ೖ͍ͯ͠Δ ಉ͡γάχνϟ

Slide 25

Slide 25 text

*'࣮૷ͷසग़ύλʔϯ package mai n import "fmt " type Password strin g // fmt.Stringer Λ࣮૷͍ͯ͠Δ func (p Password) String() string { return "***** " } func main() { fmt.Println(Password("Tokyo2020")) // **** * } Stringer ΠϯλϑΣʔεΛ࣮૷͢Ε͹ Println ౳ͰࣗಈͰద༻͞ΕΔ

Slide 26

Slide 26 text

JOUFSGBDF\^ package mai n import "fmt " func main() { anySlice := []interface{}{1, "two", 3.0 } fmt.Println(anySlice) // [1 two 3 ] anyMap := map[int]interface{}{1: "string", 2: 2.0 } fmt.Println(anyMap) // map[1:string 2:2 ] } ͳΜͰ΋ೖΔܕΛѻ͍͍ͨͱ͖͸ interface{} Λ࢖͏

Slide 27

Slide 27 text

࿅श

Slide 28

Slide 28 text

࿅श໰୊ w ࿅श໰୊ 1 <ϑΥϧμ໊EBZFY> w ·ͣ͸1ͷDIBSDPVOUͷࣸܦ͔Β w ࿅श໰୊ 1 <ϑΥϧμ໊EBZFY> w 11ͷUFNQDPOWΛNBJOύοέʔ δ಺ʹ࣮૷ɺ$FMTJVTܕ͸ઌिͷ੒Ռ෺EBZ UFNQDPOWΛJNQPSU

Slide 29

Slide 29 text

ʙղઆλΠϜʙ

Slide 30

Slide 30 text

͕࣌ؒ༨ͬͨΒʜ w ࿅श໰୊ 1 <ϑΥϧμ໊EBZFY> w ࢀߟʹͳΔϓϩάϥϜ͸1ͷEFEVQ w ࿅श໰୊ʙ 11 <ϑΥϧμ໊EBZFY\^> w 11ͷJOUTFUΛࣸܦ͔ͯ͠Β࢝ΊΔ w -FO 3FNPWF ͷ࣮૷͸Ϗοτૢ࡞ͷ஌͕ࣝඞཁ w ࿅श໰୊ 1 <ϑΥϧμ໊EBZFY> w 1ͷCZUFDPVOUFSΛࢀߟʹͯ͠࡞Δ

Slide 31

Slide 31 text

ίʔυΛॻ͖ऴ͑ͨΒ w ʮϢʔβʔ໊QSBDUJDFʯϒϥϯνͰ࡞ۀ͍ͯ͠Δ͜ͱΛ֬ೝ͍ͯͩ͘͠͞ w 74ίʔυͷҰ൪ࠨԼʹදࣔ͞Ε͍ͯ·͢ w มߋΛεςʔδ͠ɺίϛοτ͍ͯͩ͘͠͞ w 74ίʔυͷࠨϝχϡʔͷʮιʔε؅ཧʯ͔Βૢ࡞ w ίʔυΛ(JU)VCʹϓογϡ͍ͯͩ͘͠͞ w 74ίʔυͷҰ൪ࠨԼͷϒϥϯν໊ͷ͙͢ӈʹ͋ΔΞΠίϯ͔Βૢ࡞ ্ਤ w ϓϧϦΫΤετΛ࡞੒͍ͯͩ͘͠͞ w ʮιʔε؅ཧʯͷ্෦ʹΞΠίϯ͕͋Γ·͢

Slide 32

Slide 32 text

࣍ճ༧ࠂ w ࣍ճ͸ʮඪ४ϥΠϒϥϦ͸΍Ί͙ΓʯͰ͢ w ෼͔Βͳ͔ͬͨͱ͜Ζ΍࣭໰ͳͲ͸ɺࣾ಺ 4MBDLHPQIFSTνϟϯωϧʹ౤ߘ͍ͩ͘͞ w ຊ೔ͷ಺༰ΛΑΓਂ͘ཧղ͍ͨ͠ํ͸ɺڭՊॻ ͷୈষɺୈষɺୈষΛಡΜͰΈ͍ͯͩ͘͞