zoukankan      html  css  js  c++  java
  • go数据类型

    一。数值型

          1.整数

            1.1 无符号整数:u开头的类型,表示正整数和零,uint8,uint16,uint32,uint64

            1.2 有符号整数: int8,int16,int32,int64

            1.3 根据操作系统自适应的数据类型:uint,int,intptr(这种是常用类型)

                 对于 32 位系统

             uint=uint32
             int=int32
    

                 uintptr 为 32 位的指针 对于 64 位系统

             uint=uint64
             int=int64
    

                  uintptr 为 64 位的指针

          2.浮点数:根据后面接的小数数量分

             2.1 单精度浮点数:float32

             2.2 双精度浮点数:float64

          3.虚数:

             3.1 complex64

             3.2 complex128

    二. 字符串:(string)

      (一)一些重要的概念

               1.  用(双引号"")或者(``号)来描述

               2. 双引号之间的转义字符会被转义,而``号之间的转义字符保持 原样不变。

               3. 由单字节组成:类似python的列表,可以用索引来操作

      (二)字符串的操作:

              1. 求长度

              2.用索引获取某个字符

              3.字符串合并

    三。布尔型:(bool)

         1.  true / false

         2. 与: and / &&

            或:  or  / ||

            非: not / !

        3. 以下均不能作为if后的布尔判断。
            空值:nil
            零值:0
            空值:""
     
    四。类型的判断和转换
         1. 类型断言表达式
           

           container是否是[]string类型,ok为true,把container赋值给变量value。

           

        2. 类型之间的转换:

           待续。。。见第6章

    五。别名类型:

          

    六。 类型再定义,潜在类型:

          

          

    七。相关代码:

    var srcInt = int16(-255)
    dstInt := int8(srcInt)
    
    
    string(-1)
    
    
    string([]byte{'xe4', 'xbd', 'xa0', 'xe5', 'xa5', 'xbd'}) // 你好
    
    
    string([]rune{'u4F60', 'u597D'}) // 你好
    

      

     
     
     
     
     
  • 相关阅读:
    085 Maximal Rectangle 最大矩形
    084 Largest Rectangle in Histogram 柱状图中最大的矩形
    083 Remove Duplicates from Sorted List 有序链表中删除重复的结点
    082 Remove Duplicates from Sorted List II 有序的链表删除重复的结点 II
    081 Search in Rotated Sorted Array II 搜索旋转排序数组 ||
    080 Remove Duplicates from Sorted Array II 从排序阵列中删除重复 II
    079 Word Search 单词搜索
    078 Subsets 子集
    bzoj2326: [HNOI2011]数学作业
    bzoj2152: 聪聪可可
  • 原文地址:https://www.cnblogs.com/derekchen/p/9739100.html
Copyright © 2011-2022 走看看