Swift学习❤️版 --- 1、2 --- 基础和数据类型

2020-12-22  本文已影响0人  黄成瑞

用Playground来写一些简单的Swfit程序再好不过了~Playground如何使用,请进:传送门

// 变量
var a = 10
a = 20

// 常量
let b = 20
b = 10 // 报错,常量不可以改

// 打印
print(a)
print(b)
print("a的值为\(a)")
print("b的值为\(b)")
print(\(a + b))
print("a+b等于\(a + b)")
let age: Int  // 这样的方式一定要明确类型
age = 10
let a: Float = 30.0    // 扩展:a叫做标识符,30.0叫做字面量
let b = 30.0
let http404Error = (404, "Not Found")    // http404Error就是元组类型
print("The status code is \(http404Error.0)")
let (statusCode, statusMessage) = http404Error
print("The status code is \(statusCode)")
let (justTheStatusCode, _) = http404Error
let http200Status = (statusCode: 200, description: "OK")
print("The status code is \(http200Status.statusCode)")
上一篇 下一篇

猜你喜欢

热点阅读