In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the types of Swift literals". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Guided Swift is an open source programming language that supports multiple programming paradigms and compilations.
A literal quantity is a value such as a specific number, string, or Boolean value that can directly indicate its own type and assign a value to a variable. For example, in the following:
Let aNumber = 3 / / Integer literals let aString = "Hello" / / string literals let aBool = true / / Boolean literals
Integer literal quantity
The integer literal can be a decimal, binary, octal, or hexadecimal constant. The binary prefix is 0b, the octal prefix is 0o, the hexadecimal prefix is 0x, and the decimal has no prefix:
Here are some examples of integer literals:
Let decimalInteger = 17 / / 17-decimal representation let binaryInteger = 0b10001 / / 17-binary representation let octalInteger = 0o21 / / 17-octal representation let hexadecimalInteger = 0x11 / / 17-hexadecimal representation
Floating point literal quantity
Floating-point literals have integer parts, decimal points, decimal parts and exponential parts.
Unless otherwise specified, the default derivation type for floating-point literals is Double in the Swift standard library type, which represents 64-bit floating-point numbers.
Floating-point literals are represented by default in decimal (no prefix) or in hexadecimal (with prefix 0x).
A decimal floating-point literal consists of a decimal number string followed by a decimal or exponential part (or both). The decimal part consists of the decimal point. Followed by a decimal number string. The exponential part consists of an uppercase or lowercase e prefixed by a string of decimal numbers that represent the number before e times the power of 10. For example, 125 means 1.25 to 10 ^ 2, which is 125.0; similarly, 1.25e-2 means 1.25 to 10 ^-2, which is 0.0125.
The hexadecimal floating-point literal consists of the prefix 0x followed by the optional hexadecimal decimal part and the hexadecimal index part. The hexadecimal decimal part consists of a string of hexadecimal numbers followed by a decimal point. The exponential part consists of an uppercase or lowercase p prefixed by a string of decimal numbers that represent the number before p multiplied by the power of 2. For example, 0xFp2 means 15 / 2 ^ 2, which is 60; similarly, 0xFp-2 means 15 / 2 ^-2, which is 3.75.
Negative floating-point literals consist of the unary operator minus sign-and floating-point literals, such as-42.5.
Floating-point literals allow the use of underscores _ to enhance the readability of numbers, and underscores are ignored by the system, so the value of the literal is not affected. Similarly, you can add 0 to the number without affecting the literal value.
Here are some examples of floating-point literals:
Let decimalDouble = 12.1875 / / Decimal floating point literals let exponentDouble = 12.1875 / / Decimal floating point literals let hexadecimalDouble = 0xC.3p0 / / hexadecimal floating point literals
String literal quantity
A string literal consists of a string of characters enclosed in double quotes in the following form:
"characters"
String literals cannot contain unescaped double quotes ("), unescaped backslashes (\), carriage returns, or newline characters.
The following is a simple example of the literal amount of a string:
Import Cocoalet stringL = "Hello\ tWorld\ n\ nLinux should learn this from the official website:\ 'https://www.linuxprobe.com\'"print(stringL)
The execution results of the above procedures are as follows:
This is the end of Hello World's "what are the types of Swift literals"? thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 269
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.