Swift教程之运算符

Swift教程之运算符,第1张

概述import Foundation//4、复合赋值 *** 作符var a = 1a += 2//一元减运算符(一个数值前加了符号-,叫作一元减运算符)let three = 3let minusThree = -three //minusThree = -3let plusThree = -minusThree // plusThree = 3//一元加运算符(一元加运算符(+)返
import Foundation//4、复合赋值 *** 作符var a = 1a += 2//一元减运算符(一个数值前加了符号-,叫作一元减运算符)let three = 3let minusThree = -three //minusThree = -3let plusThree = -minusThree // plusThree = 3//一元加运算符(一元加运算符(+)返回的值,不做任何变动)let minusSix = 6let alsoMinusSix = +minusSix // alsoMinusSix = 6//6、三元条件运算符//特别注意:三目运算符里面的(?)前面一定要有至少一个空格let contentHeight = 40let 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.countfor i in 0..<count{    print("Person \(i) is called \(names[i])")}
总结

以上是内存溢出为你收集整理的Swift教程之运算符全部内容,希望文章能够帮你解决Swift教程之运算符所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1086617.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存