Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!
This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join 11 million other learners and get started learning Python for data science today!
Good news! You can save 25% off your Datacamp annual subscription with the code LEARNPYTHON23ALE25 - Click here to redeem your discount
القواميس
A dictionary هو نوع بيانات مشابه للمصفوفات، ولكنه يعمل باستخدام المفاتيح والقيم بدلاً من الفهارس. يمكن الوصول إلى كل قيمة مخزنة في الـ dictionary باستخدام مفتاح، والذي يمكن أن يكون أي نوع من الكائنات (سلسلة نصية، رقم، قائمة، إلخ) بدلاً من استخدام فهرس للوصول إليها.
على سبيل المثال، يمكن تخزين قاعدة بيانات لأرقام الهواتف باستخدام dictionary كهذا:
بدلاً من ذلك، يمكن تهيئة dictionary بنفس القيم باستخدام الصياغة التالية:
Iterating over dictionaries
يمكن تكرار الـ dictionaries تمامًا مثل القوائم. ومع ذلك، الـ dictionary، على خلاف القائمة، لا يحتفظ بترتيب القيم المخزنة فيه. للقيام بتكرار أزواج المفتاح والقيمة، استخدم الصيغة التالية:
Removing a value
لإزالة فهرس معين، استخدم واحدة من الصيغ التالية:
أو:
Exercise
أضف "Jake" إلى دفتر الهاتف برقم الهاتف 938273443، وقم بإزالة Jill من دفتر الهاتف.
This site is generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!
