We use cookies to improve your experience. If you continue to use our site, we'll assume that you're happy with it. :)

Introduction to Data Structure in Python

2 min read

Today engineers are hired on the basis of problem solving skills, for that you need to know Data structure for sure.

In this blog you should be aware of what is data structure and what is use of it in programming world..



Note:- In this and upcoming blogs you will learn data structure with Python Programming Language

So let's get started:

If you learn Data structure with python it will be a lot more easy to learn, if you don't understand let me show you:-

Python have built in data structures that will do your half of work very easily, they are as following:-

1> List :-

List is upgrade version of the arrays, in python if you want to use array you will have option of array that will be some tricky for you cause you have to use numpy for that but there is easier thing available for you i.e. List.

A list is collection of element that you can store in it. In arrays you can store only integer at a time but in list you can store any data type.

An array has a limited size so you have to see size in your number storing but list is dynamic it does not have fixed size so you can store n number of data inside your list.

List is mutable so you can change, add and remove elements after printing list.

List also allows Duplicacy.

List's example is:-

myList = [1,2,3,4,5,6.5,7.6,8.7,"Hi","CodeWithDevops",True]

2> Tuple

Tuple is also a collection in Python use to store values inside it. It also can store duplicate values inside it and tuple is immutable so you cannot change after printing tuple.

Tuple's example is:-


  myTuple = (1,2,3,4,5,6.5,7.6,8.7,"Hi","CodeWithDevops",True)
  

3> Set

Set is also the same as the above two but it does not allow duplicacy and it is also immutable but it can be updated.

Set's example is:-

mySet = {1,2,3,4,5,6.5,7.6,8.7,"Hi","CodeWithDevops",True}

4> Dictionary

Dictionary is also use to store values inside it but in key and value pair. In dictionary key should be always unique and value can be unique or not doesn't matter.

myDict = {

"name" : "CodeWithDevops",

"job" : "Helping others with blog",

"fav_lang" : "Python"

}


That is it that much of data structure Python provides us inside it, but you can use many more data structures.

These data structures were called as Built-in Data Structure.

What we will be seeing next be User-defined Data Structure.


Post a Comment