Hello 1 Welcome to this video.
In this video I will be talking about the string data type in Python.
Anytime you hear programmers and developers talking about string they are basically referring to text
and characters page string and python is basically a sequence of character data for the computer to
recognize that you are referring to a string.
You have to enclose or surround the text in quotes.
The quotes can be single or they can be double quotes but you cannot mix them.
You can start with a single quote and end with a double quote all characters between the opening and
closing quotes are all part of the string also a string can contain any character you want including
spaces that can also contain backslash and other kinds of characters you want included in your string
a string can also be empty so you can have an empty string.
Just have the quotes and nothing in between the quotes a typical example of his string is hello world.
So the text enclosed in quotes is what the computer we recognize as a string.
If you don't enclose it in quotes the computer will not know what you're talking about.
I have got my command prompt.
If you're on a Mac you need to open up your terminal and type in Python 3.
If you're on a Windows just type in Python to access the python shell and press enter.
I'm just going to use the print statement of function to just print out some text on the screen so I'm
gonna type in print and inside the parentheses for the print function.
I'm going to just print out a simple text and just say hello and as close as you can see I've got the
opening double code and the closing double quote and I'll close in parentheses for the print function.
Now if I press printer nitro just print out hello world without the quotes so you can see he is giving
me text.
Hello world.
So that's how the computer understands that you are talking about his strength so anytime you want to
refer to his string in Python you have to enclose it in the quotes and the codes have to be matching.
You can start with a double code here and then end with a single is you either used to single or you
used to double on either side.
So let's try another example if I say print and in quotes.
I just have a single quote and I just say hey and just close that presenter and you can see just kiss
me Hey so you can use either single or double quote.
What if you have a character that is caught.
Now you want to use an apostrophe.
How would you represent that in a string character.
So this is how you would do it.
So let's say we have the print function and inside that I want to have a string so I can say hey I'm
not typing.
What.
So you use what they call a escape character which is a backslash.
So do that and then add the single quote and I want the s on typing up and then I'll close that by doing
it this way.
It will output the apostrophe with the What's up because I've got I can't use double quotes because
I've already got the double quotes on either side enclosing the string by press enter.
You can see here says what's up.
It's now using the apostrophe.
The only way I was able to achieve that was by using this escape character to escape the sequence and
produce the this here.
OK so that's how you use that character.
All characters in a string has a specific index that is associated to them to identify their position
or location within the string.
So what that means is that you can tell what number a particular string is positioned within a string.
And with Python the index are zero based.
What that means is that the first letter of the first character will be will have the index of 0.
The next will have the index of 1 and so on.
For example now this hedge will have an index of 0.
The position will be 0 and then the E position of the E would be 1 does what is referred to as a zero
based index.
So let's cut to a quick example to see how the index works in Python so I can just do a simple print
statement and inside the parentheses which say hello.
Okay.
And then I'll close the apparently sees and then to find that the position of a specific character I
need to use a square brackets.
So for example I want to find out the position of E in a low.
It will have an index of 1 because the first has an index of 0 so I'll close the square brackets and
close the parentheses for my print function and if I press enter it should return and it should return
the value of E U C so e here as the index of 1 because it's a zero based index so knowing how indexes
works is quite useful as well.
In Python so that is it for this brief introduction to the string data type in Python.
Thanks for watching.
Bye for now.