Python Data Types Explained: Strings, Lists, Dictionaries, Tuples, and Sets

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's learn about data types in Python in programming data types specify the type of data that can be stored inside a variable which means we already know the integer data type right so we can only store whole numbers into the integer variable same in float we can all we can store pointed decimal numbers and we in strings we will pass everything in the double quotation so that is a sequence of character strings there are many other data types other than that so let's see them one by one so here is the list of data types here integers which we can in programming WR as int which stores whole numberers such as 3 300 200 then we have floating point which is a float in programming numbers with a decimal point 2.3 4.6 1.0 then strings that ordered sequence of characters which here we can see in double quote or in a single code we can pass anything you we want to give then we have another data types like list dictionaries tles sets and booleans we already know that it is a logical value indicates true or false right so let's see them in vs4 okay let me show you let's first create one new file named data types do py okay here we already know integer and Float string and Boolean right so I'm not going to go deep into that so uh firstly let me show you some detailed points about strings there are so many inbuilt functions which we can use and do cool things in strings so first let's check out that methods let's assign a one string for that first so I am going to assign one string in uh let's take a variable greeting and we will assign a value in a string format here let me write hello world okay now we have one method called inbuilt method means python provid us set methods we don't need to BU those we can directly use them so we have one method lower and one method is upper okay so upper so let's run them so we can write grating dot lower and parenthesis parenthesis you have to uh write if you want if you are accessing any functions it is is called as a function call we will see that later in detail so for now this is greetings we can use a DOT to access any inbuilt methods on strings or any other data types okay then we will print this whole because we want to see the output on the terminal so we need to use print statement for that so cover this whole thing into print statement and then run it see it converted H and W also in the lower case so this is how it works then we have another let me copy paste it and just write here upper oh upper okay so let's run this now see this is in all in lower case all in upper case these two methods was lower and upper then we have another method which is called as find method now let me show you example greeting dot find and let's say I want to find where is the W in this or let's say where is the L in this string look okay so let me write L and if I want to show the output on the terminal I need to cover this into a print statement okay so let's do that print and let me comment out this control slash and run this program see it is a showing to here it is a find function will let me show see if you can H it will show you that return the lowest index in s let me describe you all this it Returns the index of whatever character we will write here so it the index of the string starts from zero so it goes like 0 1 2 3 4 so you can see we have two L here but it will give us the out uh output where it will find the first uh matching character so first matching character that is L is on the second index so that why it returned as two okay and you can also write hello whole thing here it will give us output of starting index of the this whole string so let's run this you can see it is giving us a zero so that's how this find is find works then we have another method called replace for Strings oh Uhl let's see that so greeting dot let's say in our this main string I want to change this W to small W so I can do I can write like I want to what to change so w and with which character you want to change that so small W right and cover this in print because we want to show output on the terminal so let's Lo that and see the output see here it converted capital W into small W okay now you can also convert the whole word like I want to replace world with students stents now let's run this you can see it converted hello B into hello students so this that's all about strings method now let's move on to another uh data type so it's lists so lists are ordered collection of items it means the way you will write like 10 hello and 2.3 then it this ordered will be maintained throughout the process then and you can see here first element is integer then second is string and third is uh float so we can uh write uh different types of elements in one place using lists okay we can change add and remove items from the list using different methods of lists we will show I will show you that also then we can access the element of a list using index number and we can update the value using index number only let's see that I have already created one example folder folders for you Al so you can use this to learn so see here first if we want to declare any list you can declare it like this give a variable name and whatever you want to write in under the list you will write you can write into square brackets so one then if you want to write some name then age whatever you whatever data type you want to write and height whatever it is so this is how you can declare the list okay let me remove this for now so let me write here decaration of list so now see inbu functions for the lists okay so here I have uh declared one list in that list I have stored fruits name so I give a variable name as a fruits then there is one method upend so using append method in list we can add element in list so you can see here I have used variable fruits and to access the inbuilt method we can use dot then I have used append method and I have passed Cherry as a string into the upend so if I will run this okay let me clear this up first clear and let me comment out other things so you can focus on one okay let's let comment out this and run this program so you can see in our declared list we have only apple mango and banana and by using aend cherry is added at the last in the list so that's how upend works okay let's now comment it out and move on to other so now we have a clear so clear inbu function is used to clear all the elements from the list so we have apple mango and banana and if we use fruits do clear then it will clear all the fruits and return return us a empty string let's let me run this see here you can see empty list so that's how clear works and let's again comment it out and go to the third method which is Count see here we have a list of fruits where apple mango banana and mango so list allow us to write duplicate values so here mango is two times so what does count do to so it will like we can use fruits then dot count and we can pass one element from the list so we have WR written here mango so mango is two times in the list and we are printing this the X because we have this whole thing we have assigned in variable X okay so if we will print this we will get the output two because mango is two times and if we will write Apple then it will return as one I hope you understand that this then let's command this out and move further so here another method is pop which is used to uh Delete us remove the element at the specified position so like uh let me show you we have a least apple mango and banana in that list and if we write fruits. pop and then you have to pass a index whatever element you want to remove you can remove that by the index and then print the list again so if I will run this let me first clear okay now if I run this you can see in the zero index we have Apple so it is removed from the list and only mango and banana is printed if you want to remove mango then you can do that also let me run see apple and banana and mango is removed so that's how it it works then we have reverse method so we have a list of fruits and if we use reverse method then it will reverse the whole list like it will give us out put banana mango and then Apple see easy right then we have a short method which is very important in lists so you can see here we I have uh two list one is for fruits and one are numbers so it will short them it will short is according to AB CD and this one in 1 2 3 4 format okay so let me run this and you can see first Apple then B is banana and then mango and here you can see smallest number first two8 and 10 so this is this is how short works so this was some important methods of strings and list which uh which is very important to know for you to go further in advanced topics okay now let's move to another data type so another data type is dictionary dictionaries are used to store data value in a key value pairs to create a dictionary we use curly brackets okay this is the curly brackets and this is the key and this is value for that then again this is the key and this is the value for that key here each key should be unique like you cannot use a name uh double times every key should be unique in dictionaries okay and we can change add and remove items from the dictionaries also so let me show you example how we can declare the dictionaries okay so let me show you uh let's say I have one variable named data and I want to store a person's data in that so I have used a curly brackets then I will use a Keys okay so I will first say ID okay ID and I want to give the ID one then then we will let's say name of that person so I will say XY Z then age of that person so let's say 21 height of that person let's say 5.4 Etc so this whole thing is called as a dictionary in this is in curly brackets and key value Pairs and every key these all are key these are unique Keys No No repeated keys are allowed here okay now let's print this data so print and data and let's run this you can see it is showing the dictionary format to us now if you want to access the particular height or age or nam's value you can do that by giving the key as the parameter so data then square brackets and this is giving us see age height ID and name so we can access whatever you want to print so let's say height so it will print height for us see 5.4 and there is one ALS it can also pass list into the dictionary like subjects student has choosed okay so you can say maths and Science and now you will print subject is let's say it will print see Ma send signs a list so we can also pass list inside the dictionary okay and also can access them now we have another data type which is uh topples okay so they are ordered immutable immutable means unchangeable sequence of objects and we can declare the tole using this small brackets parenthesis and you can this is a similar to list like in list also we can write any data type you want to write see similar to list you can see here the only the difference is it list is declared in square brackets and they are ordered and ordered sequence of objects and this is ordered inmutable we can change these values in list but in tle once the values are elements are declared we cannot change them further so that's the difference between list and topple otherwise they are their work is same in list we have so many inbuilt methods but in tle we have only two methods which is count and index same as we have already shown show count in this method in a list it works similar for topple also so I'm not going to show you that then let's move to sets Okay so they are unordered collection of unique objects so sets are used to store multiple items in a single variable Whatever item declared in set we cannot change that but we can remove and add new items to it okay so this is how we can declare the set in cly brackets and you can pass whatever you want to pass okay let me show you the example so let's go to vs course and understand the sets Okay so let's first declare one sets so I will say fruits again we we will let's take some fruits name like apple banana and mango this supports multiple data types so it is not necessary that all should be in string but here I have taken this type of set okay now sets are on ordered let me first comment this out uh okay so sets are unordered by that I mean let me show you live example clear okay so let me first Rin these fruits and also let me show you the type of these fruits okay so type and then fruits and run see it is showing type as a set and you can see I have declared fruits in order to like apple banana then mango but it it is giving us output banana apple and then mango so it is on order every time you you will run it it will will uh give you us give us a different order so let me rerun it see now Apple first now Banana first now apple banana mango mango apple banana so they are whenever you print this it will give us different order so that why it is unordered so so far we have seen these all the data types and we already know the bu right so we have covered this all now we will move further to next topic congratulations on completing this module hope you enjoyed it thank you see you in the next module
Info
Channel: AI with Ritesh
Views: 174
Rating: undefined out of 5
Keywords: Python data types, Python tutorial, strings, lists, dictionaries, tuples, sets, integers, floats, booleans, built-in methods, VS Code, examples, beginners
Id: u7amBMmUamA
Channel Id: undefined
Length: 21min 14sec (1274 seconds)
Published: Thu Jun 13 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.