- 9 months ago
📌 New to Python? Start mastering STRINGS today!
In this beginner-friendly video, we’ll explore everything you need to know about Python strings — one of the most commonly used data types in any programming language.
You'll learn how to create, manipulate, and format strings in Python with hands-on examples. Whether you're building a chatbot, parsing data, or just starting out with coding, understanding strings is a key part of your Python journey. https://1stepgrow.com/advanced-data-science-and-ai-course/
In this beginner-friendly video, we’ll explore everything you need to know about Python strings — one of the most commonly used data types in any programming language.
You'll learn how to create, manipulate, and format strings in Python with hands-on examples. Whether you're building a chatbot, parsing data, or just starting out with coding, understanding strings is a key part of your Python journey. https://1stepgrow.com/advanced-data-science-and-ai-course/
Category
📚
LearningTranscript
00:00We are ready to explore the next set of executions.
00:12But to understand the next set of executions, we have to understand a couple of things.
00:18So far, the values that we are storing in our variables, the variables are only holding a single value.
00:25For example, if I would say language and if I would print the value of language, you will see the language is equal to Hindi.
00:32That means the value of the variable is holding a single value called Hindi.
00:36It's a single variable. Am I right?
00:38The variable is of type str. It's a single value variable.
00:42But sometimes we want to store more than one value in a variable.
00:48For example, a shopping list.
00:50Shopping list is that kind of variable where we would like to store many values in a particular variable.
00:59So let's create a variable called shopping underscore list.
01:04And now we want to store many values in a variable.
01:08To hold many values in a variable, we will define something called a list.
01:13Now, a list will always be put inside square brackets.
01:18Inside the square brackets, we will put list.
01:21Just like we use single quotes or double quotes to write string data, to use list, we will put square brackets.
01:27So what are the values that we are going to use in a list?
01:30For example, I want to buy apples.
01:33Followed by I want to buy some butter.
01:35Followed by I want to buy some sugar.
01:38And I want to buy some rice.
01:40So this is my shopping list right now.
01:43So these are individual elements of a particular list.
01:48So first thing what we will do is, whenever we have created a variable, we will print the variable.
01:53That's not the shopping list.
01:55So when we print the variable, now you will see that the variable is giving you an output that looks like this.
02:03The output is basically four strings.
02:06And all these strings are separated by a comma, right?
02:09And the output is encapsulated in square brackets.
02:13So a list is encapsulated in square brackets.
02:16A list can have one or more elements.
02:18And each element will be separated from the other element by a comma, right?
02:23So this is called as a list.
02:25If you want to see what the type of variable that this particular list is holding, this is holding data, which is of type list.
02:33In a list, we have four strings.
02:36Each string is separate from the other string by a comma, right?
02:39So now, inside the particular list, the elements are ordered in a particular way.
02:44For example, if I would put a comment line over here, this element is at index position zero.
02:51This element is at index position one.
02:54This element is at index position two.
02:57And this element is at index position three.
03:00Right?
03:01So what happens in a list?
03:02I have four elements.
03:04The elements start from position zero, index position zero, up to index position three.
03:10Python, like other programming language, is a zero based language.
03:16That means index positions always start from zero.
03:20It does not start from one.
03:22What is the purpose of an index position?
03:24If I want to access the first element of the list.
03:28Okay?
03:29How will I write it?
03:30I will say shopping underscore list is actually the whole list.
03:34And I will put square bracket notation and I will write the index of the element which I want to access.
03:40So it is apples.
03:42So this is the first element of the list.
03:45In fact, I can write a print statement.
03:47And I can say print the first element of the list is and I will write comma and I will say shopping underscore list index zero.
04:06So the first element of the list is apples.
04:10List can hold mixed data types.
04:16For example, you could have a variable called random list.
04:21And you could have said 10, comma, false, comma, butter, comma, pi.
04:35The pi is a variable.
04:37Right?
04:38And then if you would print the value of random underscore list, you would see that you have an integer followed by a boon, followed by a string, followed by a float.
04:50So variables can also hold mixed data types.
04:55List is an ordered data type.
04:59So because it's an order, hence we can say something like, what is the first element of the list?
05:05What is the second element of the list?
05:07What is the third element of the list?
05:09And what is the fourth element or the last element of the list?
05:13We can only use terms like first, last, second, second, last.
05:17Why?
05:18Because it's an order to the list.
05:20So tenth is the first element of the list.
05:24Pi is the variable.
05:26Pi is the last element of the list.
05:28So list is an ordered element.
05:30Ordered collection of data.
05:32Why are we putting the space?
05:33Because the code becomes easier for us to read.
05:36Even when you write plain English, when we are writing English, we put a comma and we put a space.
05:41So this is more easier for us to read.
05:43But yeah, the space is not required.
05:45Okay.
05:46In fact, you can put as many spaces as you want.
05:48It doesn't matter.
05:49Spaces are completely ignored by Python.
05:51What is important is every element will be separate from the other element by a comma.
05:55The space is not required.
05:57So we had this list called shopping underscore list, which was holding four values.
06:03Now I told you earlier that if I have to access element at index position zero, so this is the first element.
06:09So the first element is always at index position zero, right?
06:12Similarly, if I have to access the second element, how would I access the second element?
06:16I would say print.
06:17The second element is shopping underscore list at index position one, right?
06:26Index is always zero based.
06:28So index position one is the second element.
06:32Right now we are just interested in accessing the elements of the list.
06:36Okay.
06:37So we are trying to access the different element of the list.
06:39This is at element zero, one, two, three.
06:41Okay.
06:42Now, if you take a look at these lists, you can also access, if you want to get the length of the list.
06:50What is the length?
06:51Again, if you take a look at the length word, it's a keyword.
06:54LEN means the length.
06:55Okay.
06:56And it's again green in color.
06:57That means it's a special word that Python understands.
07:00So LEN is a keyword and would say shopping underscore list.
07:05So it will tell you how many elements are there in the list.
07:08Shopping list has how many elements?
07:09Four elements.
07:10So LEN of shopping list will give you the value four.
07:14That means there are four elements in the list.
07:17Right?
07:18So this also you can use it in a print statement.
07:20You can say print the number of elements in the list is comma LEN of shopping underscore list.
07:33So the number of elements in the list is four.
07:37Okay.
07:38What is LEN?
07:39LEN is a keyword.
07:40It will tell you how many elements are there in the list.
07:43Right?
07:44If I have, if I would have another element, if I would have another list called friends.
07:49And who are my friend?
07:50My friend is WALA and VIMIT.
07:53WALA, JIMIT and AMIT.
07:55How many, how many elements are there in this list called friends?
07:58So I would say LEN of friends.
08:01And I would see that a friend is a list that has got three elements.
08:07Right?
08:08Clear?
08:09Now that you know, how does LEN work?
08:12Can you tell me how to get the last element of the list?
08:18Shopping list is three.
08:21Shopping list is three.
08:24What about a code that I can write?
08:28So I can say LEN of shopping list, LEN of shopping underscore list minus one.
08:37So I would get the value rise.
08:39Similarly, if I want to get the last value of my friends list, I can say LEN of friends.
08:46What is LEN of friends?
08:48LEN of friends is equal to three.
08:49What is LEN of friends minus one is equal to AMIT.
08:52That is the last element.
08:54If I want to get the last element of a list, this is one of the ways of doing it.
08:58But this is a bit cumbersome.
09:00Okay.
09:01Python has given us even a better, better way of doing Python.
09:05What does Python do is it gives negative indexes for elements of a list.
09:12For example, if I have lists like this, I can access the list.
09:15I can access the list like this.
09:16This is element zero.
09:17This is element one, element two and element three.
09:22But I could also access the list using negative indentation.
09:26So the last element is always negative one.
09:29The last elements of the list can always be accessed by negative one.
09:33The second last is negative two.
09:35The second last is negative two.
09:37The third last is negative three.
09:40And the first element over here is negative four.
09:45Because there are four elements of the list.
09:47So this is one way of accessing the list.
09:49This is other way of accessing the list.
09:51If I want to access the last elements of the list, I could have said shopping underscore list index three.
10:02Also, I could have said shopping underscore list index negative one.
10:08This is the same value.
10:09This is the same value.
10:11Okay.
10:12This is the same value.
10:13It is the same value.
10:20Well.
Comments