Skip to content

Commit f9a2dcd

Browse files
xljxlj
authored andcommitted
fix fmt error
1 parent cb0f486 commit f9a2dcd

6 files changed

Lines changed: 15 additions & 14 deletions

File tree

117-Slices/slices-01.gop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ println nums[:2] // [1 2]
1515
println nums[2:] // [3]
1616

1717
nums[1] = 5
18-
println nums // [1 5 3]
18+
println nums // [1 5 3]

117-Slices/slices-05.gop

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
# Slice defaults
22
// When slicing, you may omit the high or low bounds to use their defaults instead.
3-
//
3+
//
44
// The default is zero for the low bound and the length of the slice for the high bound.
5-
// <pre>
5+
//<pre>
66
// For the array
77
// var a [10]int
88
// these slice expressions are equivalent:
99
// a[0:10]
1010
// a[:10]
1111
// a[0:]
1212
// a[:]
13-
// </pre>
14-
13+
//</pre>
1514
s := []int{2, 3, 5, 7, 11, 13}
1615

16+
s = s[1:]
17+
println s
18+
1719
s = s[1:4]
1820
println s
1921

2022
s = s[:2]
2123
println s
22-
23-
s = s[1:]
24-
println s

117-Slices/slices-06.gop

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ func printSlice(s []int) {
1616
s := []int{2, 3, 5, 7, 11, 13}
1717
printSlice s
1818

19-
2019
s = s[:0] // Slice the slice to give it zero length.
2120
printSlice s
2221

117-Slices/slices-07.gop

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Nil slices
22
// The zero value of a slice is nil.
3+
//
34
// A nil slice has a length and capacity of 0 and has no underlying array.
45

56
var s []int
7+
68
println s, len(s), cap(s)
9+
710
if s == nil {
811
println "nil!"
9-
}
12+
}

117-Slices/slices-08.gop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ c := b[:2]
2626
printSlice "c", c
2727

2828
d := c[2:5]
29-
printSlice "d", d
29+
printSlice "d", d

117-Slices/slices-10.gop

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Appending to a slice
22
// It is common to append new elements to a slice, and so Go provides a built-in append function. The documentation of the built-in package describes append.
3-
//
3+
//
44
// func append(s []T, vs ...T) []T
55
//
66
// The first parameter s of append is a slice of type T, and the rest are T values to append to the slice.
@@ -10,7 +10,7 @@
1010
// If the backing array of s is too small to fit all the given values a bigger array will be allocated. The returned slice will point to the newly allocated array.
1111

1212
func printSlice(s []int) {
13-
printf "len=%d cap=%d %v\n", len(s), cap(s), s
13+
printf "len = %d cap = %d %v\n", len(s), cap(s), s
1414
}
1515

1616
var s []int
@@ -24,4 +24,4 @@ s = append(s, 1) // The slice grows as needed.
2424
printSlice s
2525

2626
s = append(s, 2, 3, 4) // We can add more than one element at a time.
27-
printSlice s
27+
printSlice s

0 commit comments

Comments
 (0)