DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,864 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Ansh Gupta
Ansh Gupta

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)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.