0% found this document useful (0 votes)
13 views15 pages

exp 6

This is the my research when I am study in collage 1st yera

Uploaded by

rockeysehrawat1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views15 pages

exp 6

This is the my research when I am study in collage 1st yera

Uploaded by

rockeysehrawat1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Bharati Vidyapeeth Deemed University

College of Engineering, Pune


Department of Electronics and
Communication Engineering

Title: - Program to interchange first and last


elements in a list

1
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

SUBJECT: Python Programming Sem-II


EXPERIMENT NO – 6

AIM: To study a program to interchange first and last elements in a list

THEORY:
There are different types of data types in python like Tuple, Set, Dictionary, etc. The one that is
both changeable and ordered is called List in Python. It also allows duplicate values as a
member, wherein each member can be accessed separately in an iterative fashion. In this topic,
we are going to learn about Python List Functions.

Below is the basic syntax to define a list:

List = ["grapes" , "mangoes" , "bananas" ,"kiwi"]

print(List)

Output:

2
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

Examples of Python List Functions

Let’s discuss the various functions that can be applied.

1. In Operator

It is utilized to verify whether any specific element is a member of the list or not.

Code:

# Python code to showcase the usage of in operator

lst = [1 , 6 , 7 , 4 , 3]

# checking using in operator

if 1 in lst:

print ("1 is present in the list")

3
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

else : print ("1 is not present in the list")

Output:

2. Not In Operator

It is utilized to verify whether any specific element is not a member of the list.

Code:

# Python code to showcase the usage of not in operator

lst = [1 , 6 , 7 , 4 , 3]

# checking using not in operator

if 1 not in lst:

print ("1 is not present in the list")

else : print ("1 is present in the list")

Output:

4
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

 len(): This function returns the length of the list passed as an argument.
 min(): This function returns the minimum element of the list passed as an
argument.
 max(): This function returns the maximum element of the list passed as an
argument.

Code:

# Python code to showcase the usage of len(), max() & min() function

lst = [1 , 6 , 7 , 4 , 3]

print(len(lst))

5
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

print(min(lst))

print(max(lst))

Output:

3. + Operator

This operator is utilized to append the members of two lists together in a single one.

Code:

# Python code to understand how + operator works with lists

# creating list 1

lst = [34 , 37 , 39]

6
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

# creating list 2

lst2 = [43 , 45 , 47]

# using + operator in python to concatenate lists

lst3= lst + lst2

print(lst3)

Output:

4. * Operator

This operator is utilized to repeat the members of the list the times the operator is used
with * operator.

Code:

7
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

# Python code to understand how * operator works with lists

# creating list 1

lst = [34 , 37 , 39]

# using * operator in python to concatenate lists

lst3= lst * 2

print(lst3)

Output:

8
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

 count(): This function returns the number of times an element is present in the
list

Code:

# Python code to understand how count() function works with lists

# creating list 1

lst = [34 , 37 , 39 , 24 , 37, 37, 37, 37, 37, 37 , 37 ,37]

# using count() function with lists to understand its usage

print(lst.count(37))

Output:

9
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

 remove(): This function is utilized to remove the first occurrence of the


specified member from the list

Code:

# Python code to understand how remove() function works with lists

# creating list 1

lst = [34 , 37 , 39 , 24 , 37, 37, 37, 37 , 37 , 37 , 37 , 37, 37 , 37]

# using remove() function with lists to understand its usage

lst.remove(37)

print(lst)

Output:

10
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

Here if we notice carefully, the very first occurrence of 37 is removed from the list

 sort(): This python function is utilized to sort the list passed as an argument in
ascending order.

Code:

# Python code to understand how sort() function works with lists

# creating list 1

lst = [34 , 37 , 39 , 24 , 37, 34, 35, 38 , 36 , 33 , 17 , 25, 86 , 47]

# using sort() function with lists to understand its usage

lst.sort()

print(lst)

Output:

11
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

 reverse(): This python function is utilized to reverse the list passed as an


argument.

Code:

# Python code to understand how sort() function works with lists

# creating list 1

lst = [34 , 37 , 39 , 24 , 37, 34, 35, 38 , 36 , 33 , 17 , 25, 86 , 47]

# using sort() function with lists to understand its usage

lst.reverse()

print(lst)

Output:

12
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

 clear(): This function is utilized to empty the list passed as an argument to this
function.

Code:

# Python code to understand how sort() function works with lists

# creating list 1

lst = [34 , 37 , 39 , 24 , 37, 34, 35, 38 , 36 , 33 , 17 , 25, 86 , 47]

# using sort() function with lists to understand its usage

lst.clear()

print(lst)

The Output of this python program is:

13
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

14
Bharati Vidyapeeth Deemed University
College of Engineering, Pune
Department of Electronics and
Communication Engineering

Conclusion.

Assessment of the Experiment/Assignment:

Timely Submission Presentation Understanding Total Signature of

(07) (06) (12) (25) Teacher with date

15

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy