Professional Documents
Culture Documents
Program 2: Mutable and Immutable Types Mutable Datatype: Item1 Print Item1 Type Item1
Program 2: Mutable and Immutable Types Mutable Datatype: Item1 Print Item1 Type Item1
In [2]:
Item1.remove("175.00")
Item1
In [3]:
Item1.insert(1, "17562")
Item1
2. Sets
In [4]:
Item2 = {"Vim Bar", "Cleaning", "25.00","1800","Unilever"}
print(Item2, type(Item2))
In [5]:
Item2.add("15622")
print(Item2)
In [6]:
Item2.remove("Unilever")
Item2
3. Dictionary
http://localhost:8888/nbconvert/html/2140290_Program2.ipynb?download=false Page 1 of 3
2140290_Program2 29/07/22, 2:20 AM
In [7]:
Items = {1: "Nivea Men Facewash", 2: "Vim Bar Soap", 3: "Park Avenue Good Mornin
print(Items, type(Items))
print("Accessing a Item using key:")
print(Items[2])
{1: 'Nivea Men Facewash', 2: 'Vim Bar Soap', 3: 'Park Avenue Good Morning'}
<class 'dict'>
Accessing a Item using key:
Vim Bar Soap
In [8]:
Items2 = Items.copy()
print(Items2)
Items.clear()
print(Items)
{1: 'Nivea Men Facewash', 2: 'Vim Bar Soap', 3: 'Park Avenue Good Morning'}
{}
Immutable Datatype
Immutable is the when no change is possible over time. In Python, if the value of an
object cannot be changed over time, then it is known as immutable. Once created, the
value of these objects is permanent
Program
http://localhost:8888/nbconvert/html/2140290_Program2.ipynb?download=false Page 2 of 3
2140290_Program2 29/07/22, 2:20 AM
In [11]:
print("Welcome to DMart Items Login!!!")
ItemsData={"12545":{"Name":"Nivea Men Cream","Price":"175.00","Company":"Nivea"
Itemss={"12545":"123","12684":"234","13569":"345"}
if I in Itemss:
pwd=str(input("Enter the password:"))
if pwd==Itemss[I]:
print("Welcome")
ch= str(input("Do you want to Change Details(Yes/No):"))
if ch=="Yes":
print(ItemsData[I])
while ch=="Yes":
d=int(input("What Do you want to Change: \n1. Name \n2. Price
if d ==1:
x=str(input("Enter the New Name:"))
ItemsData[I]["Name"] = x
print("The Name has been Updated")
print(ItemsData[I])
elif d ==2:
x=str(input("Enter the New Price:"))
ItemsData[I]["Price"] = x
print("The Price has been Updated")
print(ItemsData[I])
elif d==3:
x=str(input("Enter the New Company:"))
ItemsData[I]["Company"] = x
print("The Company Name has been Updated")
print(ItemsData[I])
elif d==4:
x=str(input("Enter the New Stock:"))
ItemsData[I]["Stocks"] = x
print("The Stocks has been Updated")
print(ItemsData[I])
if ch=="No":
print("Logging Out....")
else:
print("Item doesn't exist...")
print("End of the Program")
In [ ]:
http://localhost:8888/nbconvert/html/2140290_Program2.ipynb?download=false Page 3 of 3