学习swift从青铜到王者之字符串和运算符02

1 字符和字符串初步 

var c :Character = "a"

2 构造字符串 

let str1 = "hello"
let str2 = " world"
let  str = str1 + str2
print(str)//hello world
print("hello(str2)")//hello world

数学运算符 

(+, -, *, /, %)

赋值运算符 

= , +=, -+, *=, /=, %=

关系运算符 

>, <, >=, <=, ==, !=, ?:

逻辑运算符 

1. ! 逻辑非!a a不为0时!a表达式为ture a为0时,表达式为false
2. && 逻辑与a&&ba和b全为ture 表达式才为ture
3. || 逻辑或a||ba和b最少有一个为ture 表达式为ture
注意:逻辑运算符对象必须是布尔值类型。

区间运算符

1.闭区间运算符:a...b

for icount in 1...10 {
    print(icount)//从1遍历到10(包括10)
}

2.半闭区间运算符:a..<b

for icount in 1..<10 {
    print(icount)//从1遍历到10(不包括10)
}
原文地址:https://www.cnblogs.com/jiackyan/p/7987204.html