zoukankan      html  css  js  c++  java
  • Swift 元组 Tuple

    let infoArray:[Any] = ["jack",18,1.88]

    let infoName=infoArray[0] as!String //此处为Any类型强转为String类型

    print(infoName.count)

     

     

    let infoDict:[String:Any]=["name":"jack","age":18]

    let dictName=infoDict["name"] as! String //此处为Any类型强转为String类型

    print(dictName.count)

     

    //使用数组或者字典取出的类型为Any类型

    //使用元组保存信息,能头准确的推导出数据类型

    //写法一:

    let infoTuple1=("jack",18,1.88)

    let tupleName=infoTuple1.0

    let tupleAge = infoTuple1.1

    let tupleHeight = infoTuple1.2

     

    //写法二:使用别名

    let infoTuple2=(name:"jack",age:18,height:1.88)

    print(infoTuple2.name)

    print(infoTuple2.age)

     

    //写法三:

    let (name,age,height) = ("jack",18,1.88)

    print(name)

  • 相关阅读:
    LeetCode
    LeetCode
    Django ORM 查询
    The Usage of Pymongo
    MongoDB基操
    Django内置auth模块中login_required装饰器用于类视图的优雅方式
    Django Session配置
    Python虚拟环境
    遇见Flask-Script
    Git使用手册
  • 原文地址:https://www.cnblogs.com/dhui69/p/11157377.html
Copyright © 2011-2022 走看看