ONLINE SUMMER TRAINING Online Courses Free Tutorials 
 Placement Preparation 
Artificial Intelligence(AI) & Machine Learning(ML) Training in Jaipur
0 like 0 dislike
197 views
in RTU/BTU B.Tech(CSE-VI SEM) PYTHON LAB by Goeduhub's Expert (7.6k points)
Write a program to demonstrate list  in python

Goeduhub's Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

Apply Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon

3.

Complete Machine Learning & Data Science with Python Apply Coupon

4.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

5.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon

6.

Complete Python Programming from scratch with Projects Apply Coupon

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Write a program to demonstrate list  in python

List : It is as same as arrays , it contains heterogeneous datatypes . 

eg: a=[1,2,"a"]

 a[0] =0

 print(a)

 a=[0,2,"a"]

Functions in list

append()Adds an element at the end of the list
clear()Removes all the elements from the list
copy()Returns a copy of the list
count()Returns the number of elements with the specified value
extend()Add the elements of a list (or any iterable), to the end of the current list
index()Returns the index of the first element with the specified value
insert()Adds an element at the specified position
pop()Removes the element at the specified position
remove()Removes the first item with the specified value
reverse()Reverses the order of the list
sort()Sorts the list

Program 

# Creating a List 

List = [] 

print("empty List: ") 

print(List)

 Output

empty List:

 []

# Creating a List with the use of a String 

List = ['GoEduHub.com'] 

print(List) 

Output

['GoEduHub.com'] 

# Creating a List with the use of multiple values 

List = ["Go", "Edu", "Hub",".Com"] 

print(List[0]) #accesing values of list 

print(List[1])

print(List[2])

print(List[3])

Output

Go 

Edu 

Hub 

.Com

# Creating a Multi-Dimensional List By Nesting a list inside a List

List = [['Go', 'Edu'] , ['hub.com']]  

print(List) 

Output

[['Go', 'Edu'], ['hub.com']]

# Creating a List with the use of Numbers 

List = [1, 2, 4, 4, 3, 3, 3, 6, 5]  

print(List) 

# Removing element using pop() method

List.pop() #removes last element

print(List)

 Output

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

[1, 2, 4, 4, 3, 3, 3, 6]

# Print elements from beginning to a pre-defined point using Slice 

SList = List[:-6] 

print(SList)

# Print elements using Slice operation 

Sliced_List = List[3:8]  

print(Sliced_List) 

# Print elements from a pre-defined point to end 

SList = List[5:]  

print(SList) 

# Printing elements from beginning till end 

SList = List[:] 

print(SList) 

# Creating a List with  mix  values 

List = [1, 2, 'Go', 4, 'Edu', 6, 'Hub']  

print(List)

# Printing elements in reverse using Slice operation 

Sliced_List = List[::-1]  

print(Sliced_List) 

Output

[1] 

[3, 3, 3, 6] 

[3, 6] 

[1, 2, 4, 3, 3, 3, 6] 

[1, 2, 'Go', 4, 'Edu', 6, 'Hub'] 

['Hub', 6, 'Edu', 4, 'Go', 2, 1] 

# Removing elements using Remove() method 

List = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]  

print(List) 

List.remove(5)

print(List) 

List.remove(6)  

print(List) 

Output 

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 

[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12] 

[1, 2, 3, 4, 7, 8, 9, 10, 11, 12]

# Removing elements from List using iterator

List =[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 

for i in List: 

    print(i) 

Output

1

2

3

4

5

6

7

8

9

10

11

12


For more Rajasthan Technical University CSE VI Sem Python Lab Experiments Click here

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...