官术网_书友最值得收藏!

Basic operators

Swift provides the following basic operations:

  • The = operator for assignments, similar to many different programming languages.
  • The + operator for addition, - for subtraction, * for multiplication, / for pision, and % for remainders. These operators are functions that can be passed to other functions.
  • The -i operator for unary minus and +i for unary plus operations.
  • The +=, -=, and *= operators for compound assignments.
  • The a == b operator for equality, a != b for inequality, and a>b, a<b, and a<=b for greatness comparison.
  • The ternary conditional operator, question ? answer1: answer2.
  • nil coalescing a ?? b unwraps optional a if it has a value and returns a default value b if a is nil.
  • Range operators:
    • Closed range (a...b) includes the values a and b
    • Half-open range (a..<b) includes a but does not include b
  • Logical operators:
    • The !a operator is NOT a
    • The a && b operator is logical AND
    • The a || b operator is logical OR
主站蜘蛛池模板: 汉阴县| 太保市| 铜鼓县| 正镶白旗| 深泽县| 上高县| 咸丰县| 昌平区| 沂南县| 徐闻县| 开江县| 武威市| 玛沁县| 丰原市| 乌拉特前旗| 安乡县| 连云港市| 资中县| 青川县| 三门县| 五台县| 镇雄县| 宜阳县| 滨海县| 临漳县| 炉霍县| 宁化县| 麟游县| 铜陵市| 大港区| 冷水江市| 象州县| 乌拉特后旗| 岚皋县| 海安县| 南雄市| 拜城县| 永康市| 志丹县| 龙南县| 高州市|