当前位置:网站首页>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
边栏推荐
- MMDetection模型微调
- [multimodal] clip model
- 针对语义分割的真实世界的对抗样本攻击
- [CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video
- 【双目视觉】双目立体匹配
- How do vision transformer work?【论文解读】
- 【MagNet】《Progressive Semantic Segmentation》
- Deep learning classification Optimization Practice
- 服务器的内网可以访问,外网却不能访问的问题
- Win10 solves the problem that Internet Explorer cannot be installed
猜你喜欢
Record of problems in the construction process of IOD and detectron2
What if a new window always pops up when opening a folder on a laptop
Mmdetection installation problem
【Random Erasing】《Random Erasing Data Augmentation》
mmdetection训练自己的数据集--CVAT标注文件导出coco格式及相关操作
Eklavya -- infer the parameters of functions in binary files using neural network
【多模态】CLIP模型
【Paper Reading】
Look for we media materials from four aspects to ensure your creative inspiration
Remplacer l'auto - attention par MLP
随机推荐
C#与MySQL数据库连接
Apple added the first iPad with lightning interface to the list of retro products
The hystrix dashboard reported an error hystrix Stream is not in the allowed list of proxy host names solution
Faster-ILOD、maskrcnn_ Benchmark trains its own VOC data set and problem summary
Jetson nano installation tensorflow stepping pit record (scipy1.4.1)
【BiSeNet】《BiSeNet:Bilateral Segmentation Network for Real-time Semantic Segmentation》
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video
【Mixed Pooling】《Mixed Pooling for Convolutional Neural Networks》
【雙目視覺】雙目矯正
One book 1078: sum of fractional sequences
CPU的寄存器
Traditional target detection notes 1__ Viola Jones
【MnasNet】《MnasNet:Platform-Aware Neural Architecture Search for Mobile》
【Cascade FPD】《Deep Convolutional Network Cascade for Facial Point Detection》
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
Remplacer l'auto - attention par MLP
【Paper Reading】
浅谈深度学习模型中的后门