operator
Operator is used to execute program code operations, which are performed on one or more operand items. For example: 2 + 3, whose operands are 2 and 3, while the operator is "+". So "+,-, *,/" are all operators.
What kinds of operators are there?
The main operators in the swift language include arithmetic, relationships, logical operators, and so on.
Arithmetic operators: +,-, *,/,%, + +,--etc.
+: Adds a sum operation, and can also be used for string-type connection operations.
-: Reduce the calculation of the difference.
*: Multiply the quadrature operation.
/: Except rounding operations.
%: remainder operation.
+ +: Self-added i++ means first to take the value plus one, ++i means to add and repeat the value.
---: self-subtraction I--means that the first value and then minus one,--I means to reduce the number of repeated values.
Relational operators: <, = =, >=, <=,! =, etc.
Logical operator:! (non), && (with), | | (or) and so on.
In addition to some of the commonly used operators mentioned above, there are some other operators:
. : an operator of a reference, an instance call property, a method, and so on.
? : Used to declare an optional type.
! : A forced unpacking of an optional type value.
-A: Describes the method return value type.
:: Used for dictionary collection to split key-value pairs.
In these operators, some operators that require only one operand are called the monocular operator (or unary operator). Such as:
Logical non-operator "! ", the self-decrement operator" + + ","--", the minus sign operator"-", The pointer operator" * "and the Fetch address operator" & ", and so on.
An operator that requires two operands is called a binocular operator, such as:
Arithmetic operators: "+", "-", "*", "/", "%", relational operator: "<", ">", "= =", ">=", "<=", "! =", logical operator: "& ;& "," | | | " such as.
An operator that requires three operands is called a trinocular operator, and the trinocular operator is only "?:".
An expression
In Swift, there are 3 forms of expression: No data type specified, data type specified, use "; ".
Do not specify a data type:
Specify the data type:
Use "; " :
Be careful you will find that in swift language, a statement can end without adding "; "Can also be added"; ", but there is a situation which must be used"; , that is, when multiple statements are written in one line, you need to differentiate the statements by semicolons.
#从零开始学Swift2.0# No.2 operators and expressions