Go Example--range
package main
import "fmt"
func main() {
nums := []int{2,3,4}
sum :=0
//rang 遍历切片
for _,num := range nums {
sum += num
}
fmt.Println("sum:",sum)
for i,num := range nums {
if num == 3 {
fmt.Println("index:",i)
}
}
kvs := map[string]string{"a":"apple","b":"banana"}
//range遍历map
for k,v := range kvs{
fmt.Printf("%s-> %s\n",k,v)
}
//range遍历字符串
for i,c := range "go" {
fmt.Println(i,c)
}
//range还可以遍历channel
}
Go Example--range的更多相关文章
- SQL Server 合并复制遇到identity range check报错的解决
最近帮一个客户搭建跨洋的合并复制,由于数据库非常大,跨洋网络条件不稳定,因此只能通过备份初始化,在初始化完成后向海外订阅端插入数据时发现报出如下错误: Msg 548, Level 16, S ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- [LeetCode] Range Addition 范围相加
Assume you have an array of length n initialized with all 0's and are given k update operations. Eac ...
- [LeetCode] Count of Range Sum 区间和计数
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
- [LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- [LeetCode] Range Sum Query 2D - Immutable 二维区域和检索 - 不可变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- [LeetCode] Range Sum Query - Immutable 区域和检索 - 不可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- C++11中自定义range
python中的range功能非常好用 for i in range(100): print(i) 现在利用C++11的基于范围的for循环特性实现C++中的range功能 class range { ...
随机推荐
- ural1519
题解: 插头dp 具体可以看看cdq论文 代码: #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ...
- WPS处理个人信息一种方法
下面是WPS处理个人信息的方法,具体步骤如下: 第一步:任意打开一个文件: 第二步:点击左上角WPS的小三角,找到工具——选项,如图: 第三步:进入选项后,点击用户信息: 第四步:修改个人信息,用户名 ...
- iPhoneX && iOS11 适配
最近实在是蛮闲的,这都得益于苹果爸爸给力的审核,已经半个月了(委屈) 这个问题已经很久了,但是还是希望分享给各位,当然网上的教程的确很多: 1.automaticallyAdjustsScrollVi ...
- 使用keytool生成公钥、私钥、证书并且读取出来,使用私钥签名jar并验证(转)
参考链接:http://happyqing.iteye.com/blog/2139504 :https://blog.csdn.net/arjelarxfc/article/details/52461 ...
- 牛客多校第二场 G transform
链接:https://www.nowcoder.com/acm/contest/140/G White Cloud placed n containers in sequence on a axes. ...
- Ubuntu下teamviewer的安装
安装i386库 1.sudo apt-get install libc6:i386 libgcc1:i386 libasound2:i386 libexpat1:i386 libfontconfig1 ...
- 关于urls 的基础
1 普通正则 2 分组正则 url(r'/blog/(\d+)/(\d+)',views.blog) blog(request,arq1,arq2) 按照位置传参 3 分组命名 url(r'/ ...
- Fedora 10编程开发工具
1请问Fedora 10编程开发工具有什么 编辑器就用vim,编译用gcc,当然个人爱好随意 IDE的话推荐eclipse,如果做C/C++的,用codeblocks也是个不错的选择 输入gcc -v ...
- python day02--运算符,编码
一.格式化输出 %s: 字符串的占位符, 可以放置任何内容(数字)%d: 数字的占位符 age="18"name="小明"print("我叫%s&qu ...
- PaddlePaddle tutorial
什么是PaddlePaddle PaddlePaddle,百度旗下深度学习开源平台.Paddle(Parallel Distributed Deep Learning,并行分布式深度学习). 2016 ...