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

רשימות


Lists דומות מאוד למערכים. הן יכולות להכיל כל סוג של משתנה, והן יכולות להכיל כמה משתנים שתרצו. ניתן גם לבצע איטרציה על רשימות בצורה פשוטה מאוד. הנה דוגמה לבנייה של רשימה.

גישה לאינדקס שאינו קיים יוצרת חריגה (שגיאה).

Exercise

בתרגיל זה, תצטרכו להוסיף מספרים ומחרוזות לרשימות הנכונות באמצעות שימוש בשיטת "append" של רשימות. עליכם להוסיף את המספרים 1,2, ו-3 לרשימת "numbers", ואת המילים 'hello' ו-'world' למשתנה strings.

תצטרכו גם למלא את המשתנה second_name עם השם השני ברשימת names, תוך שימוש באופרטור סוגריים []. שימו לב כי האינדקס מתחיל מ-0, ולכן אם תרצו לגשת לפריט השני ברשימה, האינדקס שלו יהיה 1.

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!

Previous Tutorial Next Tutorial Take the Test
Copyright © learnpython.org. Read our Terms of Use and Privacy Policy