当前位置:网站首页>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
边栏推荐
- 【学习笔记】Matlab自编高斯平滑器+Sobel算子求导
- Gensim如何冻结某些词向量进行增量训练
- 【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
- How to turn on night mode on laptop
- 【双目视觉】双目立体匹配
- 【FastDepth】《FastDepth:Fast Monocular Depth Estimation on Embedded Systems》
- open3d学习笔记三【采样与体素化】
- Open3d learning note 4 [surface reconstruction]
- 【多模态】CLIP模型
- TimeCLR: A self-supervised contrastive learning framework for univariate time series representation
猜你喜欢

Installation and use of image data crawling tool Image Downloader

open3d学习笔记三【采样与体素化】

Faster-ILOD、maskrcnn_ Benchmark training coco data set and problem summary

【雙目視覺】雙目矯正

超时停靠视频生成
![[binocular vision] binocular correction](/img/fe/27fda48c36ca529eec21c631737526.png)
[binocular vision] binocular correction

Common machine learning related evaluation indicators

Replace convolution with full connection layer -- repmlp

Feature Engineering: summary of common feature transformation methods

EKLAVYA -- 利用神经网络推断二进制文件中函数的参数
随机推荐
Look for we media materials from four aspects to ensure your creative inspiration
I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?
Comparison of chat Chinese corpus (attach links to various resources)
【C#笔记】winform中保存DataGridView中的数据为Excel和CSV
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
What if the laptop task manager is gray and unavailable
[mixup] mixup: Beyond Imperial Risk Minimization
Implementation of yolov5 single image detection based on onnxruntime
Translation of the paper "written mathematical expression recognition with bidirectionally trained transformer"
Daily practice (19): print binary tree from top to bottom
open3d学习笔记四【表面重建】
Handwritten call, apply, bind
【FastDepth】《FastDepth:Fast Monocular Depth Estimation on Embedded Systems》
Semi supervised mixpatch
【学习笔记】Matlab自编图像卷积函数
【Paper Reading】
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video
【MobileNet V3】《Searching for MobileNetV3》
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
(15) Flick custom source