Swift学习笔记之基本数据类型-基本运算符

1. 代码示例

//: Playground - noun: a place where people can play

import Cocoa

//赋值运算符
let name = "Hello World"
print(name+"\n")


//数值运算符
var num1 = 3
var num2 = 1
var sum = num1 + num2
print(sum)

//比较运算符
if(num1 > num2){
    print("The bigger number is \(num1)")
}else{
    print("The bigger number is \(num2)")
}

//三目运算符
let num3 = 100
let num4 = 200
var biggerNum = num3 > num4 ? num3 :num4
print(biggerNum)
2. 运行结果

Swift学习笔记之基本数据类型-基本运算符_第1张图片

你可能感兴趣的:(swift)