Swift教程之运算符
发布时间:2020-12-14 02:02:16 所属栏目:百科 来源:网络整理
导读:import Foundation//4、复合赋值操作符var a = 1a += 2//一元减运算符(一个数值前加了符号-,叫作一元减运算符)let three = 3let minusThree = -three //minusThree = -3let plusThree = -minusThree // plusThree = 3//一元加运算符(一元加运算符(+)返回
import Foundation //4、复合赋值操作符 var a = 1 a += 2 //一元减运算符(一个数值前加了符号-,叫作一元减运算符) let three = 3 let minusThree = -three //minusThree = -3 let plusThree = -minusThree // plusThree = 3 //一元加运算符(一元加运算符(+)返回的值,不做任何变动) let minusSix = 6 let alsoMinusSix = +minusSix // alsoMinusSix = 6 //6、三元条件运算符 //特别注意:三目运算符里面的(?)前面一定要有至少一个空格 let contentHeight = 40 let rowHeight = contentHeight + (contentHeight > 20 ? 50 : 20) //7、范围运算符 //封闭范围运算符(包括a和b) for index in 1...5 { print("(index) times 5 is (index * 5)") } //半封闭的区域运算符(包头不包尾) let names = ["Anna","Alex","Brian","Jack"] let count = names.count for i in 0..<count { print("Person (i) is called (names[i])") } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |