1. package main
  2. import "fmt"
  3. func main() {
  4. nums := []int{2,3,4}
  5. sum :=0
  6. //rang 遍历切片
  7. for _,num := range nums {
  8. sum += num
  9. }
  10. fmt.Println("sum:",sum)
  11. for i,num := range nums {
  12. if num == 3 {
  13. fmt.Println("index:",i)
  14. }
  15. }
  16. kvs := map[string]string{"a":"apple","b":"banana"}
  17. //range遍历map
  18. for k,v := range kvs{
  19. fmt.Printf("%s-> %s\n",k,v)
  20. }
  21. //range遍历字符串
  22. for i,c := range "go" {
  23. fmt.Println(i,c)
  24. }
  25. //range还可以遍历channel
  26. }

Go Example--range的更多相关文章

  1. SQL Server 合并复制遇到identity range check报错的解决

        最近帮一个客户搭建跨洋的合并复制,由于数据库非常大,跨洋网络条件不稳定,因此只能通过备份初始化,在初始化完成后向海外订阅端插入数据时发现报出如下错误: Msg 548, Level 16, S ...

  2. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  3. [LeetCode] Range Addition 范围相加

    Assume you have an array of length n initialized with all 0's and are given k update operations. Eac ...

  4. [LeetCode] Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

  5. [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 ...

  6. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  7. [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 ...

  8. [LeetCode] Range Sum Query - Immutable 区域和检索 - 不可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  9. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  10. C++11中自定义range

    python中的range功能非常好用 for i in range(100): print(i) 现在利用C++11的基于范围的for循环特性实现C++中的range功能 class range { ...

随机推荐

  1. 笨办法06字符串(string)和文本

    代码如下: # coding : utf-8 x = "There are %d types of people." % 10 binary = "binary" ...

  2. 跑caffe过程中的备忘

    1*1卷积比如一张500*500且厚度depth为100的图片在20个filter上做1*1卷积,那么结果大小为500*500*20 只有池化改变图片的大小 一个大的全连接层可以理解为一个神经网络,这 ...

  3. 主机访问虚拟机centos7的服务器

    一.虚拟机开启桥梁接 1.编辑-->虚拟网络编辑器 2.虚拟机-->设置 二.Centos的配置---关闭防火墙下的服务器接口 Centos7.0 默认使用firewall作为防火墙,这里 ...

  4. 四:(之四)基于已有镜像构建自己的Docker镜像

    4构建自己的Docker镜像 4.1常用命令: 等同于docker commit 将一个被改变的容器创建成一个新的image 等同于docker build 通过Dockerfile创建一个image ...

  5. :组合模式:Component

    #ifndef __COMPONENT_H__ #define __COMPONENT_H__ #include <iostream> #include <vector> us ...

  6. SQL-34 对于表actor批量插入如下数据

    题目描述 对于表actor批量插入如下数据CREATE TABLE IF NOT EXISTS actor (actor_id smallint(5) NOT NULL PRIMARY KEY,fir ...

  7. Linux可重入函数和线程安全的区别与联系(转)

    *****可重入函数 函数被不同的控制流程调用,有可能在第一次调用还没返回时就再次进入该函数,这称为重入. 当程序运行到某一个函数的时候,可能因为硬件中断或者异常而使得在用户正在执行的代码暂时终端转而 ...

  8. <codis><jodis>

    Overview For codis and jodis. Codis TBD... Jodis Java client for codis. Jodis is a java client for c ...

  9. day 33 线程池有关的

    # cpu 的核心数# import os# print(os.cpu_count()) ## 爬虫的进程和线程的应用# 第一步 虚拟一个浏览器下载 在cmd 里输入 pip install requ ...

  10. nginx——绑定 Nginx 进程到不同的 CPU 上

    为什么要绑定 Nginx 进程到不同的 CPU 上 :默认情况下,Nginx 的多个进程有可能跑在某一个 CPU 或 CPU 的某一核上,导致 Nginx 进程使用硬件的资源不均,因此绑定 Nginx ...