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

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
主站蜘蛛池模板: 沧州市| 阿合奇县| 高邮市| 福清市| 徐州市| 湘西| 梨树县| 通江县| 车险| 天长市| 漯河市| 油尖旺区| 确山县| 长治县| 洮南市| 宁都县| 云浮市| 侯马市| 南丹县| 罗江县| 蒲江县| 嵩明县| 镇远县| 英吉沙县| 呈贡县| 新田县| 苍山县| 余庆县| 东明县| 泰兴市| 正定县| 阿克| 万盛区| 霍山县| 柞水县| 景洪市| 永安市| 略阳县| 余江县| 紫阳县| 新安县|