0% found this document useful (0 votes)
9 views5 pages

Python List and Tuple Operations Guide

Uploaded by

vineetanema94
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)
9 views5 pages

Python List and Tuple Operations Guide

Uploaded by

vineetanema94
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

PROGRAM 1

#create a list of the following numbers and print them with their index
l=[22,45,67,89,6,1,34,56,89,10]
print('Index-[0]:',l[0])
print('Index-[1]:',l[1])
print('Index-[2]:',l[2])
print('Index-[3]:',l[3])
print('Index-[4]:',l[4])
PROGRAM 2
#CREATE A LIST NAMED FRIENDS AND INCLUDE ELEMENTS LIKE NAME,DATE OF BIRTH,LUCKY
NUMBER,FAVROUITE COLOUR,WEIGHTAND HEIGHT.
name=input('enter name:')
lucky_no=int(input('enter lucky no.:'))
fav_colour=input('enter favorite colour:')
w=int(input('enter weight:'))
h=int(input('enter height:'))
friends=[]
[Link]([name,lucky_no,fav_colour,w,h])
print(friends)
PROGRAM 3
#Calculate the total number of zeroes,positive and negetive elements in the list.
l=[23,4,56,-1,0,46,-8,-9,0,-11,31,21]
z=0
p=0
n=0
for i in range(len(l)):
if l[i]==0:
z+=1
elif l[i]>0:
p+=1
else:
n+=1
print('total no. of zeros in the list are:',z)
print('total no. of positive numbers in the list are:',p)
print('total no. of negetive numbers in the list are:',n)
PROGRAM 4
#TUPLE SLICING
#Accessing tuple elements using slicing
my_tuple=('p','r','o','g','r','a','m')
#elements 2nd to 4th index
print(my_tuple[1:4])
#elements begining from 2nd
print(my_tuple[:-7])
#elements 8th to end
print(my_tuple[7:})
#elements begining to end
print(my_tuple[:])
PROGRAM 5

You might also like