美文网首页
2.Swift - 变量和常量

2.Swift - 变量和常量

作者: IOXusu | 来源:发表于2020-07-12 00:56 被阅读0次
    //var声明一个变量
    var a = 42
    a = 50
    //let声明一个常量,注意,b =50这句会报错,因为你不能给一个常量再次赋值
    let b = 30
    //b = 50
    //你还可以声明变量的类型,而不是使用类型推断
    var c:Int = 20
    

    2.1字符串输出的几种形式:
    (1). +

    let lable = "This width is "
    let width = 94
    let widthLabel = lable + String(width)
    print(widthLabel)
    > This width is 94
    

    (2).( )

    let apples = 3
    let oranges = 5
    let appleSummary = "I have \(apples) apples."
    print(appleSummary)
    

    (3)."""

    let quotation = """
    abcd
    efg
           hijk
    """
    print(quotation)
    

    2.2数组和字典

    var shoppingList = ["catfish", "water", "tulips"]
    print(shoppingList[0])
    var occupations = [
        "Malcolm":"Captain",
        "Kaylee":"Mechanic",
    ]
    print(occupations["Malcolm"])
    //增加数据
    shoppingList.append("blue paint")
    

    相关文章

      网友评论

          本文标题:2.Swift - 变量和常量

          本文链接:https://www.haomeiwen.com/subject/rfnwcktx.html