当前位置:网站首页>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
边栏推荐
- The difference and understanding between generative model and discriminant model
- How to clean up logs on notebook computers to improve the response speed of web pages
- Mmdetection installation problem
- TimeCLR: A self-supervised contrastive learning framework for univariate time series representation
- CPU的寄存器
- Eklavya -- infer the parameters of functions in binary files using neural network
- 【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
- MoCO ——Momentum Contrast for Unsupervised Visual Representation Learning
- mmdetection训练自己的数据集--CVAT标注文件导出coco格式及相关操作
- Mmdetection trains its own data set -- export coco format of cvat annotation file and related operations
猜你喜欢
[binocular vision] binocular stereo matching
浅谈深度学习模型中的后门
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
【BiSeNet】《BiSeNet:Bilateral Segmentation Network for Real-time Semantic Segmentation》
Faster-ILOD、maskrcnn_ Benchmark trains its own VOC data set and problem summary
Implementation of yolov5 single image detection based on onnxruntime
Graph Pooling 简析
MoCO ——Momentum Contrast for Unsupervised Visual Representation Learning
[in depth learning series (8)]: principles of transform and actual combat
Look for we media materials from four aspects to ensure your creative inspiration
随机推荐
Implementation of yolov5 single image detection based on pytorch
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
用MLP代替掉Self-Attention
半监督之mixmatch
【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》
【MobileNet V3】《Searching for MobileNetV3》
用MLP代替掉Self-Attention
Solve the problem of latex picture floating
MMDetection模型微调
Command line is too long
【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》
ABM thesis translation
Prompt 范式简述
【MagNet】《Progressive Semantic Segmentation》
Timeout docking video generation
【MobileNet V3】《Searching for MobileNetV3》
CPU register
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
Correction binoculaire
PPT的技巧