Swift Learning first day---constant variable underlying data type

Source: Internet
Author: User

1 Import Foundation2 3 /**4 * 1. Constant variables5 Knowledge Essentials: Definitions of constants with a let variable defined with VAR6 constants can no longer be changed once they are defined. 7 variable definitions can be modified anywhere in the program after the definition. 8 */9 //Definition of ConstantsTenLet Constants1:int =Ten One  APrint"constants1 = \ (constants1)") -  - //definition of a variable thevar variables1:int = One -  -Print"variables1 = \ (variables1)") -  + //difference - //constants1 = n;//here will be an error, cannot assign to value: ' Constants1 ' was a ' let ' constant. You cannot assign a value to Constants1 because it is a constant.  +  AVariables1 = A //variables can be assigned to them at any time.  at  - /** - * 2. int integer - Knowledge Essentials: When defining the shaping, be aware that the data is out of bounds, and when the data is out of bounds, the system directly - The int types include: int Int8 Int16 Int32 Int64, each type has a different range of values.  - int-9223372036854775808 to 9223372036854775807 in int8-128 to 127 - int16-32768 to 32767 to int32-2147483648 to 2147483647 + int64-9223372036854775808 to 9223372036854775807 - */ thevar a1:int8 =122 *Print"A1 is value: \ (A1)") $ Panax Notoginseng //A1 = *;//because A1 is defined as int8, its value range is 128 to 127 direct, and now gives A1 value is greater than its range, so the system prompt error, error code is integet literal ' "overflows when stored into ' Int8 ' -  the  + /** A * 3. Float type float Double the Tip of knowledge: Be aware of the cross-border, when crossing the bounds, the system will be rounded up according to the crossing proximity values.  + */ - //define a float variable $var f1:float =1.11111 $Print"F1 is value: \ (F1)") -F1 =1.111119; -Print"F1 after crossing: \ (F1)") the //define a double variable -var f2:double =2.22222222222222222WuyiPrint"F2 is value: \ (F2)") the  - /** Wu * 4. Character type - Knowledge Point: It has a value of only one character About */ $var c1:character ="A" -  - //C1 = "AB";//this will cause an error, indicating that a string type cannot be assigned to a character type -  A /** + * 5. String the Knowledge Essentials: Add, delete, merge ...  - */ $ //Add thevar s1:string ="Jerr" theS1.append (Character ("y"))//Add a character theS1.append (Unicodescalar (0x41))//Add a Unicode scalar thePrint"S1 is value: \ (S1)") -  in //Merging thevar s2:string ="and Tom" thevar s3:string = S1 +S2 AboutPrint"S3 is value: \ (S3)") the  the //Delete theS3.removeatindex (S3.startindex)//Delete the S3 at the beginning of the index +Print"S3 Removeatindex: \ (S3)") -  theS3.removeall ()//ClearBayiPrint"S3 removeall \ (S3)")

Swift Learning first day---constant variable underlying data type

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.