Python Programming Lab 1-10
Python Programming Lab 1-10
li.remove(3)
print(li)
li.append(9)
print(li)
n = len(li)
print("The length of list is ",n)
li.clear()
print(li) #empty list
3. Create a tuple and perform the following methods
add items
len()
check for item in tuple
access items
-----------------------------------------------------------
tu = (1,2,3,4,5,6)
print("The original tuple is ", tu)
tu = tu+(7,8)
print(tu)
n = len(tu)
print("The length of tuple is ", n)
pos = tu.index(4)
print("The position of 4 in tuple is ", pos)
print(tu[4]) #Print element at index 4
print(tu[2]) #Print element at index 2
9. Write a python program to add some days to your present date and print
the date added
import datetime
date = datetime.datetime.now().date() #present day
date += datetime.timedelta(days=5) #adding days
print(date)
10.Write a program to count the number of characters in the string and store
them in a dictionary data structure
s = input("Enter a string: ")
d = {}
for i in s:
if i in d:
d[i]+=1
else:
d[i]=1
print(d)