Skip to main content

List - Data type in python

 


List

                  A ‘list’ one of the data structure in Python, which holds different data in order for example: Just imagine that when you are going to a store to get at least ten or twenty different products, so if you memorized all the name of different products in the mind, you might get confused or forget in-store while shopping, So instead of getting forget or confused you would store all the in a list, whereas in Python List is used to store data in a sequence manner.

In Python, while writing a list you have to write the value inside the square bracket “[]”, which makes the Python interpreter understand that you are specifying a type ‘list’. After creating a list, you can add, remove, and search for any items in the list. Due to the capability of adding and removing the data in a list, it is also known as “Mutable data type”, which means this data can be altered.


Input:

This_is_my_list = []

type(this_is_my-list)

Output:

list


Here you can use “append” to add the data, and you can use “pop” to remove the data.


For example

Here we can write code from the described above example shopping list, we can make a shopping list and add numbers, names of the products for better understanding, we can also store, retrieve and remove data, from the ‘list’.


  1. Here in the below code, we are trying to create a list and find its type.


Input: 

  shopping_list =[]

  type(shopping_list)

Output:

  list

Here shopping list is a variable, and [] is denoted to the data structure ‘list’, and ‘type’ is a function that is used to find the data type of the variable.


2) Here we are inserting a value inside the variable ‘shopping_list’

Input:

shopping_list.append(30)

shopping_list.append(‘Mango’)

shopping_list

Output:

[20, 30 , ’Mango’ ]

Here ‘append’ is used to insert an item from the variable ‘shopping_list’. In the list, we can enter the data or an item one by it can’t enter all the items or data at a time.


3) Here we are removing an item from the variable ‘shopping_list’

Input:

shopping_list.append()

Output:

‘Mango’

Input:

shopping_list

Output:

[20, 30]


Important point while inserting a value in the variable in the ‘list’, it will assign the value one by one from the beginning by the indexing value, and while you ‘pop’ a value, it will remove the value from the end to first that why in the above code while you pop the last value ‘mango’ has removed, in the next code you can learn about indexing.


4)Here I will teach you how the computer index is assign and the length of the value.

  Input:

shopping_list

Output:

[20, 30]


Input:

Shopping_list[0]

Output:

20

Input:

shopping_list[1]

Output:

30

Input:

shopping_list.pip(0)

Output:

20


Here in the above code for every value, the computer assigns the index from ‘0’ as 0,1,2,3,4,5……….. for each value, you can ‘retrieve’ the data from the middle by using the index number and you can even ‘pop or remove’ the data from the middle by using the index number, And even you can change or replace the value by using the index number, because of its ability to remove the data and retrieve and alter the value in between. ‘len’ is used to measure the length of the value. 


Input:

A = [1, 2, 3, 4, 5, 8]

A

Output:

[1, 2, 3, 4, 5, 8]

Input:

len(A)

Output:

6

Input:

A[1]

Output:

2

Input:

A[4] = ‘Hello’

A

Output:

[1, 2, 3, 4, ’Hello’, 8]



    Thank You


         

Comments

Popular posts from this blog

A Useful information about Python programming language for Beginners

Summary About the Python Blog                             In the below-given link, you can know about the useful information about Python programming language  https://megrathdinold.blogspot.com/p/python-programming.html  , https://megrathdinold.blogspot.com/p/data-structures-in-python.html   Which is mainly important in Machine learning, AI, and Deep Learning. Which describes about Python, Advantages of Python, and uses of python. It also makes you understand the exact difference in Python when compared to other programming languages. It also makes you understand what is the use if we learn the Python Programming language. I have posted the blog in the above link, for the beginners in a short message, which makes you move forward to learn Python programming with confident.                                     ...

Sets - Data type in python

Set                     Set is also one of the Data structure in python, the set is ever simple to understand, it also contains curly bracket ‘{}’ , but the only thing it will not accept duplicate value which is the same values. Let’s understand by code, Input: D = {20, 42, 111, 20, 434, ”uk”} type(D) Output: set Input: D Output: {111, 20, 42, 434, ”uk”}‘ Input: D[3] Output: --------------------------------------------------------------------------- TypeError                                 Traceback (most recent call last) <ipython-input-48-846febc3581b> in <module> ----> 1 D [ 3 ] TypeError : 'set' object is not subscriptable                            ...

Tuple - Data type of python

  Tuple                              The tuple is one of the data structures in python. A tuple is used to store multiple values in a variable, but the values after once entered cannot be changed, that’s why it is called immutable. For example, just consider that, you have gone to a restaurant or a hotel, so to pay the money you will get a bill which contains price, tax, etc, the values which are entered in these variable, like price, tax, etc… can not be change cone it is printed, likewise in ‘tuple’ when the values are entered once it cannot be changed. the tuple is represented as curve becker ‘()’ . Let us try with an example Input: Hotel_bill = (10,20,22,) Hotel_bill Output: (10, 20, 22) Input: type(hotel_bill) Output: tuple Input: hotel_bill[2] Output: 22 ...

Dictionary - Data type of python

  Dictionary Dictionary is one of the data structure in python, which holds a value with a key, it acts as an address book, for example just consider that while you apply ar fill different forms for the admission, each form is identified with a different name, and in the form, each column has a label, like (“Age:-_23_), here the name of the form is considered as a variable to store information, the ‘Age’ is considered as the keyword, and ‘23’ is considered as the value entered to the ‘keyword’ for  ‘Age in the inside the variable form. It is denoted by curly bracket ‘{}’. Lets try with an example Input: A = {} type(A) Output: dict # dict is the short cut for Dictonary. Input: A[‘what is your name’] = ‘jack’ A Output: {‘what is your name’ : ‘jack’} Input: A[‘what is your name’] Output: ‘Jack’ Input: A[‘jack’] ------------------------------------------------------------------------...

Data Structure in python

  Data Structure in python  The data structure is one of the different and a special type of formate that is used for storing, processing,  retrieving , and, organizing the data. In other words, we can say that data structure is one of the techniques used to hold the data and use the data in an effective way , it is about rendering the data elements in terms of relationship, for better organizing and storing the data. Data structures are used in different field like  1) Artificial Intelligence 2)Graphics 3)Compiler design 4)Numerical Analysis 5)Simulations 6)Database Management System 7)Statistical Analysis Package 8)Opertating System Types of Data Structure and their uses  In Python it has four data structures, they are  1) List 2) Tuple 3) Dictionary and 4) Set.       Thank You             

Python Programming

                                        Introduction about Python  Python was created by Guido van Rossum and it was first released in 1991, it has considered as the top ten programming language in the TIOBE Programming Community Index , Python is the easiest programming language for beginners, it is a powerful tool in different platforms like HTML, Application Development, Machine learning, etc. Coding in Python is very simple compared to other Object-Oriented languages, it is easy to understand the code and easy to write. Python is an interpreter  (which means it execute the code line by line, there is no need of compiling as a group of code) and it is a freely available opensource library available for all operating systems in    https://www.python.org/ , in this same website you can find different tools, programs, and additional details. It is a high-level and gene...