Welcome back.
In this video, we're going to look at other data types, such as booleans.
So for example.
Bullion is a type which represents logical values, so it can have two possible values, true and false.
So we have this variable called is Sunny and I'm going to make it to bullion and now I'm going to sign
true to it, let's say a little later.
The sun is not shining anymore.
Then I can just say it's sunny is going to be false.
So I reassigned a new value to it.
So I assign faults to it now.
So Sunny or is Sunny will now be false?
Of course, I don't need to assign the Boolean to it or I do need to explicitly state that I want to
use it as a boolean, because once I assign a boolean value such as true to it, it will know that his
son is going to be a boolean type.
Then there is another type which is called character or char, so you can assign a char by using the
postoffice so you can see the value letter char is just an A and I make this a char by assigning a value
or a letter in this case which is surrounded by apostrophes.
So if we look at letter char, we can see it's of type char which is character.
Did it, did the cha is also of type char.
It's really not that much of a difference.
It doesn't matter if it's an a, a one or even a dollar sign, but as you can see, it cannot contain
more than one sign.
That's the limitation of char.
So a string is basically a connection of multiple chars.
It's just multiple chars together.
In this case, it's five chars which come together to becoming a string.
Now that we talk about strings, let's have a look at strings a little more.
So let's assume we have this string variable, which is called my string or my star, and it has the
text Hello World.
Now, if I want to access a certain character from that string, what I can do is I can use the following
approach.
So I'm going to call this one first char in string and this will be my string.
That's the position zero y zero.
Well, because Cutline is a language which starts calculating or counting at zero.
There are other programming languages which start counting at one such as R, but most programming languages
start counting at zero.
So zero is the first letter.
So if we print this now, let's say we want to print this first char in string.
So let's just do that first character.
And we run this code.
So let me.
Run it again and we see first char or first character is H.
All right, so in the world, the first character was, in fact, H.
If you want to get the last character, what you can do is the following.
So I'm just going to paste it in here.
Last character and string will be again my string and then in square brackets I use my string that length.
With this I get the length of the whole string and then I say minus one, which says, OK, give me
the last one, because if the length is in this case, 11.
So five characters here then one, which is this empty space and then another five characters become
two, 11 characters.
So 11 minus one is going to be 10.
So we're going to get the 11th position, which is going to be the D.
So now let's just print out the last character.
And we can see this last character is deep, which is, in fact, hello world with the.
All right.
So summing it up, there are multiple different types that we can use when we create variables.
Variables are immutable.
If we use the key word and they are immutable, so changeable if we use the VA keyboard, then we don't
have to specifically state what kind of data type we want to use if we assign the right value to it.
If we assign a value, which is of a specific type, such as a number, which is a whole number, it
will automatically assume that we want to have an integer.
So if we want to have a bite or short, for example, then we need to explicitly state that by.
Creating the variable with that type and with long numbers, we can use an underscore in order to make
it more readable.
This is a new feature that is super useful.
We can use that for string for integers as well.
By the way, this makes them more readable.
And the same concept goes for doubles as well, where it assumes that we want to assign a double if
it's a floating point number.
But if we want to specifically use a float, then we have to state that by adding an F to the number
itself.
Then there is the tie bullion, which is used to only have two states, so either something is true
or something is false, which is a super useful and we will use that quite a bit.
And we have characters which we can use in order to just one use one character, which doesn't have
to be a character, but it can also be a number or a symbol.
Then we have String's, which is a collection of a bunch of characters which we can use for text.
And if we want to print something out, we can use this print statement, which then prints it onto
our console, which is this little area here at the bottom, which helps us to test stuff and test if
a certain variable has a certain value.
Of course, there are other ways to do so, but the print statement is a very convenient one.
And another one important aspect, and I told you multiple times, but I really want to state that again,
you don't have to specifically state your data type because of type inference.
And maybe I'm going to add this word here type interference, which just means that.
Finds out the type from context, which is super powerful and useful and makes our life a lot easier
in most cases.
So let's say see you in the next one.