当前位置:网站首页>Go functions make, slice, append
Go functions make, slice, append
2022-07-02 07:56:00 【kq1983】
make
// Length and capacity are 5 Elements
array := make([]string,5)
for i:=0;i<len(array);i++ {
array[i] = strconv.Itoa(i) // int to string
fmt.Printf("%d=%s \n",i,array[i])
}
fmt.Println()
// The length is 3 individual Capacity of 5 individual
array1 := make([]string,3,5)
for i:=0;i<len(array1);i++ { // You can visit 3 Elements
array1[i] = strconv.Itoa(i) // int to string
fmt.Printf("%d=%s \n",i,array1[i])
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
0=0
1=1
2=2
3=3
4=4
0=0
1=1
2=2
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
slice
[start:end]
slice := [] int {1,2,3,4,5,6,7,8,9}
slice1 := slice[2:5]
fmt.Printf("\n")
fmt.Printf("slice1.length=%d \n",len(slice1))
for i:=0;i<len(slice1);i++ {
fmt.Printf("%d=%d \n",i,slice1[i])
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
Output
slice1.length=3
0=3
1=4
2=5
- 1.
- 2.
- 3.
- 4.
[i:j:k]
The length is j-i , Capacity of k-1
append
slice := [] int {1,2,3,4,5,6,7,8,9}
fmt.Printf("start myappend =============================\n")
// 3,4,5
slice1 := slice[2:5]
fmt.Printf("\n")
fmt.Printf("slice1.length=%d \n",len(slice1))
for i:=0;i<len(slice1);i++ {
fmt.Printf("%d=%d \n",i,slice1[i])
}
// 6 become 10 7 Turned into 11
slice1 = append(slice1,10,11)
fmt.Printf("\n")
fmt.Printf("slice.length=%d \n",len(slice))
for i:=0;i<len(slice);i++ {
fmt.Printf("%d=%d \n",i,slice[i])
}
fmt.Printf("\n")
fmt.Printf("slice1.length=%d \n",len(slice1))
for i:=0;i<len(slice1);i++ {
fmt.Printf("%d=%d \n",i,slice1[i])
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
Output
start myappend =============================
slice1.length=3
0=3
1=4
2=5
slice.length=9
0=1
1=2
2=3
3=4
4=5
5=10
6=11
7=8
8=9
slice1.length=5
0=3
1=4
2=5
3=10
4=11
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
Be careful
6 become 10 7 Turned into 11
边栏推荐
- 浅谈深度学习模型中的后门
- AR系统总结收获
- Sorting out dialectics of nature
- 将恶意软件嵌入到神经网络中
- [Sparse to Dense] Sparse to Dense: Depth Prediction from Sparse Depth samples and a Single Image
- 【TCDCN】《Facial landmark detection by deep multi-task learning》
- 【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》
- In the era of short video, how to ensure that works are more popular?
- ABM thesis translation
- [mixup] mixup: Beyond Imperial Risk Minimization
猜你喜欢
![[learning notes] matlab self compiled Gaussian smoother +sobel operator derivation](/img/f1/4afde3a4bf01254b3e3ff8bc659f9c.png)
[learning notes] matlab self compiled Gaussian smoother +sobel operator derivation

程序的执行

Memory model of program

Translation of the paper "written mathematical expression recognition with bidirectionally trained transformer"

How to turn on night mode on laptop

程序的内存模型

【FastDepth】《FastDepth:Fast Monocular Depth Estimation on Embedded Systems》
![[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video](/img/bc/c54f1f12867dc22592cadd5a43df60.png)
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video

Look for we media materials from four aspects to ensure your creative inspiration

【Mixup】《Mixup:Beyond Empirical Risk Minimization》
随机推荐
【Mixed Pooling】《Mixed Pooling for Convolutional Neural Networks》
【DIoU】《Distance-IoU Loss:Faster and Better Learning for Bounding Box Regression》
CPU的寄存器
【学习笔记】Matlab自编高斯平滑器+Sobel算子求导
MMDetection模型微调
What if a new window always pops up when opening a folder on a laptop
【Programming】
Summary of solving the Jetson nano installation onnx error (error: failed building wheel for onnx)
【MnasNet】《MnasNet:Platform-Aware Neural Architecture Search for Mobile》
[Sparse to Dense] Sparse to Dense: Depth Prediction from Sparse Depth samples and a Single Image
AR系统总结收获
Mmdetection installation problem
Installation and use of image data crawling tool Image Downloader
【BiSeNet】《BiSeNet:Bilateral Segmentation Network for Real-time Semantic Segmentation》
超时停靠视频生成
解决latex图片浮动的问题
Use Baidu network disk to upload data to the server
半监督之mixmatch
Where do you find the materials for those articles that have read 10000?
[binocular vision] binocular correction