diff --git a/Dictionary.py b/Dictionary.py index 026ded0..a6796ad 100644 --- a/Dictionary.py +++ b/Dictionary.py @@ -1,20 +1,39 @@ - +#Dictionary is a key value pairs def main(): - #Student={'Name':"hussein alrubaye",'Age':27,'Slary':232.5}; + #Creating a dictionary Student=dict(Name="hussein alrubaye",Age=27,Slary=232.5); + + #it can also be created as:- + #Student={'Name':"hussein alrubaye",'Age':27,'Slary':232.5}; + + + #we can assign a list,tuple or even a dictionary to a key in a dictionary + + #Replacing the value of a key Student['Name']="Hussein Ahmed" + + #Adding a key value pair in the dictionary Student["Dept"]="software engineer" + + #Printing the type of an dictionary print(Student,type(Student)) + + #Deleting the a key from the dictonary del Student["Dept"] - print(Student,type(Student)) + + #Accessing the value from a key print(Student['Name']) print(Student['Age']) + + #Removing all the items from the dictionary Student.clear() + print(Student,type(Student)) -if __name__ == '__main__':main() +if __name__ == '__main__': + main() diff --git a/TuplesAndList.py b/TuplesAndList.py index 2acb371..57cb545 100644 --- a/TuplesAndList.py +++ b/TuplesAndList.py @@ -3,17 +3,18 @@ def main(): #string Data="software engineer" + #String Slicing print(Data[0:5]) #List Ages=[44,33,45,33,54] Ages.append(100) - Ages.insert(0,33) + Ages.insert(0,33)#insert with index value print(Ages) #Tuples - Ages=[44,33,45,33,54] - Ages.append(100) - Ages.insert(0,33) - print(Ages) + Ages_tp=(44,33,45,33,54)#A tupple is immutable i.e, it cannot be changed + Ages_tp.append(100) + Ages_tp.insert(0,33) + print(Ages_tp)