42                 // 整型字面量3.14159            // 浮点型字面量"Hello, world!"    // 字符串型字面量true               // 布尔型字面量

打印输出

Swift 使用 print 函数打印输出:

print("Runoob") // 输出 Runoob

print 函数是一个全局函数,完整的函数签名为:

public func print(items: Any..., separator: String = default, terminator: String = default)

如果我们想让其不换行输出,只需要将最后一个参数赋值为空字符串即可:

for x in 0...10{
    print("(x) ", terminator: "")}print()

输出结果为:

0 1 2 3 4 5 6 7 8 9 10

如果你需要接收用户的输入可以使用 readLine():

let theInput = readLine()