基本運算符dom
1.賦值spa
let a = 100指針
var b = 13code
var c = 45orm
var d = 43對象
func sum(a: Int,b: Int)->Int{it
return a+bclass
}引用
var s = sum(100, b: 200)margin
print(s)
*/
//元組
/*
var (x,s) = (100, "two")
print(x)
print(s)
2.算術運算
var a = Int(arc4random()%100)
var b = Int(arc4random()%100)
print("a=\(a)")
print("b=\(b)")
var r = a+b
print("a+b=\(r)")
3.自增自減
4.複合運算
var s = 100
s+=100
print(s)
s-=50
print(s)
s*=3
print(s)
s/=2
print(s)
5.比較運算
var a = Int(arc4random()%100)
var b = Int(arc4random()%100)
print("a=\(a)")
print("b=\(b)")
print("a<b=\(a<b)")
class person {
}
var p1 = person()
//var p2 = p1 對象比較的是引用或指針
var p2 = person()
print(p1===p2)//必需要三個等號
6.三目運算
var a = 100
var b = 200
print(a>b ? a:b)
7.區間運算
//...閉區間
for i in 0...10{
print(i)
}
//..<半閉區間
for a in 0..<10{
print(a)
}
8.邏輯運算
var a = 1,b = 2 ,c = 3
var b2 = true
print(!b2)
print(a>b&&b>c)
print(a<b||b>c)