Sharp Tutorial
List in python

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

Introduction to Python

  • Introduction to Python
  • History of Python
  • How To Install Software
  • Variables in Python
  • Comments in Python
  • Input/Output
  • If else in Python
  • While Loop
  • For Loop

Collection in Python

  • Numbers in Python
  • List
  • Tuple
  • Set
  • Dictionary
  • Array
  • String

Object Oriented python

  • Function
  • Exception
  • OOPS (class/object)
  • Object Pass & Return
  • Constructor
  • Function Overloading
  • Module in Python
  • Inheritance
  • File Handling

Python With MYSQL And Excel

  • Connect MySql & Python
  • Insert Data MySQL
  • Delete/Update MySQL
  • Select Data From MySQL
  • Working With Excel in Python

Python GUI

  • GUI using Turtle
  • Introduction to Tkinter
  • Login Page using Tkinter
  • Data Grid Example Tkinter
  • Connect Multiple Forms
  • Database with GUI Python

Programs in Python

  • Swap two number
  • Calculate the area
  • Even Odd or Zero
  • Largest ,Middle and Smallest Number
  • Calculate Telephone Bill
  • Print Table of The given Number
  • Factorial of the number
  • Reverse and check number is palindrome
  • check number is prime , armstrong
  • Program to Print the given patterns
  • Guess A Number Game using Random

List in Python

List in the Python is a collection and can be used to store with dynamic size.
List is orderd and changable in nature.
List can be declared as following and the all items of the list can be printed with single print command.

myList=["India","Pakistan","USA"]
print(myList)

    Output:
    [‘India’, ‘Pakistan’, ‘USA’]

Here output elements are ordered and printed as they are stored.

Access an element of List.

myList=["India","Pakistan","USA"]
myList[2]="Russia" # this line changes the value "USA" to "Russia"
print(myList[2]) #This is how we can print only specific position element of List.

    Output:
    Russia

To Display all elements of List for loop can also be used

myList=["India","Pakistan","USA"]
for i in myList:
print(i)

    Output:
    India
    Pakistan
    USA

Important operations that can also be implemented on List

1) append(): this appends the given element at the last of the list.

myList=["India","Pakistan","USA"]
myList.append("UK")
print(myList)

    Output:
    [‘India’, ‘Pakistan’, ‘USA’, ‘UK’]

2) insert(): this method insert the given element at given index of the list.

myList=["India","Pakistan","USA"]
myList.insert(1,"UAE")
print(myList)

    Output:
[‘India’, ‘UAE’, ‘Pakistan’, ‘USA’]

3) remove(): this removes the given element from the list.

myList=["India","Pakistan","USA"]
myList.remove("Pakistan")
print(myList)

    Output:
    [‘India’, ‘USA’]

4) del(): this can delete the specific position element or the complete list

myList=["India","Pakistan","USA"]
del(myList[1])
print(myList)

    Output:
    [‘India’, ‘USA’]

myList=["India","Pakistan","USA"]
del(myList)
print(myList)

    Output:
   error as list is no more.

5) reverse(): This reverse the elements of the list

myList=["India","Pakistan","USA"]
myList.reverse()
print(myList)

    Output:
    [‘USA’, ‘Pakistan’, ‘India’]

6) clear(): It removes all the elements from the list.

myList=["India","Pakistan","USA"]
myList.clear()
print(myList)

    Output: No Elements 

7) pop(): It gives the last element of the list as in Stack.

myList=["India","Pakistan","USA"]
print(myList.pop())

    Output: USA

8) sort(): this arranges the elments of a list in an order . By default it arranges in ascending order.

myList=["India","Pakistan","USA"]
myList.sort()
print(myList)
#to arrange in reverse order
myList.sort(reverse=True)
print(myList)

    Output:    [‘India’, ‘Pakistan’, ‘USA’]

[‘USA’, ‘Pakistan’, ‘India’]

 

9) index: This returns the imndex of the given element in the list.

myList=["India","Pakistan","USA"]
print(myList.index('Pakistan'))

    Output:
    1 (index of element in list).

10) len(): This gives the length of the List.

myList=["India","Pakistan","USA"]
print(len(myList))

    Output:3

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial