Skip to content

Improved Dictionary.py #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions Dictionary.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 6 additions & 5 deletions TuplesAndList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down