Task 2
Task 2
Syntax:
a="hello"
b="WORLD"
b1="1234"
c="This is a python program"
d="I am a student of BBSBEC, BBSBEC is an Engineering college"
print(a.capitalize()) # Converts the first character to upper case
print(a.center(20)) # Returns a centered string
print(d.count("BBSBEC")) # Returns the number of times a specified value occurs in a string
print(d.find("student")) # Searches the string for a specified value and returns the position
print("In",b,"L is present at",b.index("L")) # Searches the string for a specified value and returns the position
if a.isalpha(): # Returns True if all characters in the string are in the alphabet
print(a,"is Alphabet")
if a.islower(): # Returns True if all characters in the string are lower case
print(a,"is Lowercase")
2200485 Page 5
Output:
2200485 Page 6
Task 5: WAP to demonstrate all functions of List.
Syntax:
l1 = ['apple', 'banana', 'cherry']
l2=['SUV','BMW','Enova',47,23,12,47]
l3=['hello!','hello!']
l1.append('orange') # Adds an element at the end of the list
print(l1)
print("47 is present",l2.count(47),"times in list") # Returns the number of elements with the specified value
point=(1,2,3,4)
l3.extend(point) #Add elements of list to the current list
print(l3)
print(l2.index('SUV')) # Returns the index of the first element with the specified value
l=[7,3,4,9,1,2]
l.pop() # Removes the element at the specified position
print(l)
2200485 Page 7
Output:
2200485 Page 8
Task 6: WAP to demonstrate all functions of Tuple.
Syntax:
tupl=('hello','bye',1,1,1,2,3,4,4,0)
n=tupl.index(0) #Searches the tuple for a specified value and returns the position of where it was found
print("0 is present at index",n)
Output:
2200485 Page 9
Task 7: WAP to demonstrate all functions of Dictionary.
Syntax:
stud={
'name':'Pankaj',
'roll_no':45,
'branch':'CSE'
}
new=stud.copy() #Returns a copy of the dictionary
print(new)
D=('key1','key2','key3')
d=1
Dict=dict.fromkeys(D,d) #Returns a dictionary with the specified keys and value
print(Dict)
item=stud.items() #Returns a list containing a tuple for each key value pair
print(item)
x=Dict.setdefault('key3','2') #Returns the value of the specified key. If the key does not exist: insert the key,
with the specified value
print(x)
2200485 Page 10
Output:
2200485 Page 11
Task 8: WAP to demonstrate all functions of Set.
Syntax:
fruits = {"apple", "banana", "cherry"}
x.difference_update(y) #Removes the items in this set that are also included in another, specified set
print(x)
x1.intersection_update(y1) #Removes the items in this set that are not present in other, specified set(s)
print(x1)
2200485 Page 12
x2 = {"apple", "banana", "cherry"}
y2 = {"google", "microsoft", "apple"}
z2 = x2.symmetric_difference(y2) #Returns a set with the symmetric differences of two sets
print(z2)
x2.symmetric_difference_update(y2) #Inserts the symmetric differences from this set and another
print(x2)
n1={1,2,3,1}
n2={3,4,5}
n3=n1.union(n2) #Return a set containing the union of sets
print(n3)
n1.update(n2) #Update the set with the union of this set and others
print(n1)
Output:
2200485 Page 13