DEV Community

Ansh
Ansh

Posted on

Learn With Me:Apple's Swift Literals

Hello guys and Welcome to Learn With Me: Apple's Swift.In previous tutorial you learned about Variables and Constants and today we are going to learn about Literals .So without wasting time let's start.

Literals

Literals are representations of fixed values in a program. They can be numbers, characters, or strings, etc. For example, "Hello, World!", 12, 23.0, "C", etc.
Swift supports 4 types of
literals,that are:
Integer Literals
Floating-point Literals
Boolean Literals
String and Character Literals.
So let's study about them in brief.

Integer Literals

Integer literals are those that do not have a fractional or an exponential part.

There are four types of integer literals in Swift:
•A decimal number, with no prefix.
•A binary number, with a 0b prefix.
•An octal number, with a 0o prefix.
•A hexadecimal number, with a 0x prefix.

Floating-Point Literals

Floating-point literals are numeric literals that have floating decimal points or they are in fraction. For example,

let radius:Float=7.008
Enter fullscreen mode Exit fullscreen mode

Here,7.008 is a floating-point literal assigned to the radius constant.

Boolean Literals

There are only two Boolean Literals:true and false.
For example,

let pass:Bool=true
Enter fullscreen mode Exit fullscreen mode

Character Literals

Character literals are Unicode characters enclosed in double quotes.For example,

let char:Character="S"
Enter fullscreen mode Exit fullscreen mode

String Literals

String literals are sequences of characters enclosed in double quotes.For example,

let name:String="Jonathan"
Enter fullscreen mode Exit fullscreen mode

Conclusion

Thanks for reading.I hope you will enjoy learning it.If you have any issues then let me know in the discussions.And in next part we are going to learn about Data Types in Swift.

Top comments (0)