"Swift" Learning Notes (ii)--basic operators

Source: Internet
Author: User

Operators are the most used in programming, including unary, two, and ternary three operators. Swift is just as basic as other programming languages, and here's a summary of it, as well as its unique operators. For example interval operators


1, unary operators

= assignment operator, the most used, with no matter what the return value

+ addition (numbers added, can also be used for character stitching var ss = "A" + "B")

- Subtraction

* Multiplication

/ Division

% redundancy (minus sign ignored, floating point can also be redundant)

> greater than

< less than


2, two-dollar operator

+ + + self-increment (that is, i = i + i abbreviation, can be pre-++i, able to post i++, is the same, the predecessor: self-increment and return. Back: Back to self-increment)

--Self- subtraction (equals i = i-i)

+ = i + = A is a shorthand for i = i + A

- = Ibid.

= = equals

! = does not equal

>= greater than or equal to

<= less than or equal to


3, ternary operator (trinocular operator)

= = = Identical to infer whether two objects refer to the same instance of an object

!== not identical

?: question? The answer is true: The question is a false answer such as Var a=0;print ("\ (a>0?

1:2) ") Output 2

a...b Full closed interval contains a and b

A.. <b semi-closed interval contains a does not contain B


4, logical operator.   && | | Non-or (with and or the first condition satisfied will not calculate the second one.) This is a short-circuit calculation)


New operators:

1. The null-fit operator can be understood as a shorthand for the three-mesh operator

A??

B (A! = nil?)

A! : b), meaning that A is empty and return B is not NULL returns a.




"Swift" Learning Notes (ii)--basic operators

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.