Skip to main content

DATATYPE – PYTHON LISTS AND SLICING


DATATYPE – PYTHON LISTS AND SLICING

Python lists are the most versatile and useful datatype. Lists can store a sequence of data within it, which are separated by comma and enclosed inside square brackets. The good feature of Python Lists is, the data or items stored can be of mixed data types like strings, integer, float, etc. which can be stored into a single sequence.
Example:

List1 = ["A", 21, 78, "Red", 50, "Apple"]
In this way a list is created, items inside the list are separated by a comma and string is always stored into double quote as explained earlier.
Usually when there is multiple data stored inside an array, list, tuple, etc. the indexing of it starts from zero. For example List1[0] = ‘A’ and it ends on n-1. There are many other ways of accessing items inside a list as explained in my video. You can perform addition of two or more lists. Lets see something more about Lists in detail.

Some functions to be used with Lists are:

Ø ListName.append(): This function is used to add the value into the List.
Ø del ListName[index number]: This  function will delete a particular item which is mapped using the index number.( For example, del List1[2]; This will delete the integer 78 from the existing list).
Ø len (ListName): This function will give the total number of items present inside your List.
Ø max(ListName): This function gives the maximum value inside the List. When the list consists only integers, it gives maximum or largest integer present. When the list consists only strings, it gives the longest string which has the most numbers of characters. It does not work when the Lists are having items of mixed data types.
Ø min(ListName): This function gives the minimum value inside the List. Same concept applies here for integer, string and mixed data types as in max().
Ø ListName.count(any item): This function is used to count the repetition of particular item in your list.

So in this way you can create a Python List, access it, append new values, remove the existing values, count the number of repetition of particular items, get the length or total count of items inside a list, get the minimum and maximum value in your list.







Comments

Popular posts from this blog

COMPARISON, LOGICAL, ASSIGNMENT AND BITWISE OPERATORS

COMPARISON, LOGICAL, ASSIGNMENT AND BITWISE OPERATORS In this blog we will see about Arithmetic operators and understand how to use it with Python IDLE to perform certain calculations. PYTHON COMPARISON OPERATORS OPERATOR DESCRIPTION EXAMPLE        == Checks whether LHS is equal to RHS, then the condition becomes true 10==10 is true        != Checks whether LHS is not equal to RHS, then the condition becomes true 2!=3 is true        > Checks whether LHS is greater than RHS, then the condition becomes true 6>3 is true        < Checks whether LHS is less than RHS, then the condition becomes true 6<10 is true        >= Checks whether LHS is gre...

BUILT INS FUNCTIONS IN PYTHON

BUILT INS FUNCTIONS IN PYTHON Every programming languages have certain pre-defined functions. Similarly, for certain tasks python has built in functions which you can access and understand as explained in the video.   dir(__builtins__): This module will return all the built in function and identifiers directly available to the programmer.   help(“function name”): This is the most important function in python. It gives the complete detail regarding the function which you mentioned inside help().

WHILE LOOP IN PYTHON

WHILE LOOP IN PYTHON Loops are used to execute a piece of code or set of statements multiple times in a program as long as the condition is true. While loop is the basic loop structure in Python. Syntax: While (expression):             Statement(s) Here, condition may be any logical expression and statement(s) can be single statement or multiple statements. The loop will iterate or execute until the condition is true. When the condition becomes false, program comes out of the loop and remaining statements are executed. In Python language, during any of the decision making, control statements and looping indentation is very important because, it specifies the set of statements to be a part of single code or block. Since no brackets are used to specify the complete code with in, indentation is used. Flowchart: In While loop, the main important thing is the loop may never be executed if the condition is...