בחזרה לקורס

Python Essentials 1 - קורס הכנה להסמכת PCEP

0% הושלם
0/0 Steps
  1. היכרות עם הסמכת PCEP ושפת התכנות פייתון

    ברוכים הבאים לקורס Python Essentials 1!
  2. סילבוס הקורס Python Essentials 1
  3. למה כדאי ללמוד פייתון?
  4. איפה ומתי משתמשים בפייתון?
  5. השג את הסמכת PCEP
  6. הנחה בלעדית לקורסי פייתון בשיתוף סייבר סקול ו-Python Institute!
  7. רכישת הקורס Python Essentials 1 בפורמט ספר
  8. מודול 1: מבוא לפייתון ותכנות מחשבים
    Python Essentials 1: הקדמה על מודול 1
  9. כיצד תכנית מחשב עובדת?
  10. שפות טבעיות לעומת שפות תכנות
  11. קומפילציה מול אינטרפרטציה
  12. אז מה זה פייתון?
  13. גרסאות של פייתון
  14. איך להשיג את פייתון ואיך להשתמש בה
  15. התכנית הראשונה שלי - איך לכתוב ולהריץ את התוכנית הראשונה שלך בפייתון
  16. סיכום מודול 1: מבוא לפייתון ותכנות מחשבים
    1 מבחן
  17. מודול 2: סוגי נתונים, משתנים, פעולות קלט-פלט בסיסיות, ואופרטורים בסיסיים
    הקדמה למודול 2: סוגי נתונים, משתנים, פעולות קלט-פלט בסיסיות, אופרטורים בסיסיים
  18. כתיבת תוכנית Python פשוטה: Hello, World!
  19. פונקציית Print
    1 נושא
  20. פונקציית Print - המשך
  21. ליטרלים
  22. אופרטורים
  23. אופרטורים - המשך
  24. משתנים
  25. מחרוזות
  26. בוחן סיכום מודול 2
    1 מבחן
  27. מודול 3: ערכים בוליאניים, ביצוע מותנה, לולאות, רשימות ועיבוד רשימות ופעולות לוגיות
    ערכים בוליאנים

יש יותר מסוג אחד של פייתון

ישנם שני סוגים עיקריים של פייתון: Python 2 ו-Python 3.

Python 2 היא הגרסה הישנה יותר, והפיתוח שלה נעצר בכוונה, אך עדיין מתבצעים עדכונים שמטרתם לתקן באגים וחורי אבטחה. למרות שפיתוחה הועבר לתחזוקה בלבד, Python 2 עדיין נמצאת בשימוש נרחב במערכות קיימות רבות.

Python 3 היא הגרסה החדשה יותר (והנוכחית) של השפה, והיא עוברת תהליך אבולוציוני משלה. Python 3 אינה תואמת ל-Python 2, כלומר סקריפטים שנכתבו ב-Python 2 לא יפעלו בסביבת Python 3 ולהיפך. כדי להריץ קוד Python 2 ב-Python 3 יש צורך לבצע התאמות ושינויים בקוד, אך תהליך זה אינו אוטומטי.

הבדלים בין הגרסאות: Python 3 אינה רק שדרוג של Python 2, אלא שפה שונה לחלוטין. למרות שהן דומות במבט ראשון, ישנם הבדלים משמעותיים ביניהן. אם אתה מתחיל פרויקט חדש, מומלץ להשתמש ב-Python 3, שכן כל גרסה חדשה של Python 3 היא תאימה לאחור עם גרסאות קודמות של Python 3.

בקורס זה, נשתמש ב-Python 3, וכל דוגמאות הקוד נבדקו על גרסאות Python 3.4, 3.6, 3.7 ו-3.8.

פייתון, או CPython

בנוסף ל-Python 2 ו-Python 3, יש גרסאות שונות לכל אחת מהן. הגרסאות שמפותחות על ידי קרן פייתון (Python Software Foundation – PSF) מכונות “פייתון קנוני” והן נחשבות לסטנדרט שעליו מתבססות כל שאר הגרסאות. גווידו ואן רוסום יצר את הגרסה הראשונה של פייתון בשפת C, וכל הגרסאות שמגיעות מה-PSF כתובות גם הן ב-C, מה שמאפשר להן לרוץ על רוב הפלטפורמות.

זו הסיבה שהגרסה של PSF מכונה לעיתים קרובות CPython, והיא הפופולרית ביותר מבין כל הגרסאות של פייתון.

Cython

משפחת פייתון כוללת גם את Cython, שהיא פתרון לבעיה של חוסר יעילות בפייתון. בעוד שקל לכתוב קוד מתמטי מורכב בפייתון, זמן הריצה שלו עלול להיות ארוך מאוד. Cython מתרגם אוטומטית את הקוד הכתוב בפייתון לשפת C, מה שמשפר משמעותית את מהירות הביצוע.

Jython

Jython היא גרסה נוספת של פייתון, כאשר ה-“J” מייצג את Java. מדובר בגרסה של פייתון שנכתבה בשפת Java במקום בשפת C. זהו פתרון מעשי עבור מפתחים העובדים עם מערכות מורכבות וגדולות שנכתבו בג’אווה, ורוצים להוסיף גמישות של פייתון למערכות אלו.

מכיוון ש-C ו-Java הן שפות שונות בתכלית, קשה לשלב את CPython בסביבה המבוססת על ג’אווה, ולכן Jython מספקת תקשורת יעילה יותר עם התשתית הקיימת של Java. חשוב לציין שהגרסה הנוכחית של Jython מבוססת על הסטנדרטים של Python 2, ולא קיימת עדיין גרסה של Jython התואמת ל-Python 3.

PyPy ו-RPython

PyPy היא סביבה שמאפשרת להריץ קוד פייתון בתוך פייתון אחר. למעשה, PyPy נכתבה בשפת RPython (Restricted Python), שהיא תת-קבוצה של פייתון. הקוד של PyPy לא מתבצע כפרשנות אלא מתורגם לשפת C ומבוצע בנפרד.

זה שימושי במיוחד כאשר רוצים לבדוק תכונות חדשות שאולי ייכנסו ל-Python המרכזית בעתיד. PyPy היא כלי חשוב למפתחי פייתון ומשתמשת בגרסאות Python 2 ו-Python 3.

הקורס הזה יתמקד בעיקר ב-CPython, אך חשוב לדעת שיש גרסאות רבות אחרות של פייתון בעולם, שכל אחת מהן מתאימה לצרכים שונים.


There is more than one Python

There are two main kinds of Python, called Python 2 and Python 3.

Python 2 is an older version of the original Python. Its development has since been intentionally stalled, although that doesn’t mean that there are no updates to it. On the contrary, the updates are issued on a regular basis, but they are not intended to modify the language in any significant way. They rather fix any freshly discovered bugs and security holes. Python 2’s development path has reached a dead end already, but Python 2 itself is still very much alive.

Python 3 is the newer (or to be more precise, the current) version of the language. It’s going through its own evolutionary path, creating its own standards and habits.

These two versions of Python aren’t compatible with each other. Python 2 scripts won’t run in a Python 3 environment and vice versa, so if you want the old Python 2 code to be run by a Python 3 interpreter, the only possible solution is to rewrite it, not from scratch, of course, as large parts of the code may remain untouched, but you do have to revise all the code to find all possible incompatibilities. Unfortunately, this process cannot be fully automatized.

It’s too hard, too time-consuming, too expensive, and too risky to migrate an old Python 2 application to a new platform, and it’s even possible that rewriting the code will introduce new bugs into it. It’s easier, and more sensible, to leave these systems alone and to improve the existing interpreter, instead of trying to work inside the already functioning source code.

Python 2 vs. Python 3 concept

Python 3 isn’t just a better version of Python 2 – it is a completely

different language, although it’s very similar to its predecessor. When you look at them from a distance, they appear to be the same, but when you look closely, though, you notice a lot of differences.

If you’re modifying an old existing Python solution, then it’s highly likely that it was coded in Python 2. This is the reason why Python 2 is still in use. There are too many existing Python 2 applications to discard it altogether.

NOTE

If you’re going to start a new Python project, you should use Python 3, and this is the version of Python that will be used during this course.

It is important to remember that there may be smaller or bigger differences between subsequent Python 3 releases (e.g., Python 3.6 introduced ordered dictionary keys by default under the CPython implementation) – the good news, though, is that all the newer versions of Python 3 are backward compatible with the previous versions of Python 3. Whenever meaningful and important, we will always try to highlight those differences in the course.

All the code samples you will find during the course have been tested against Python 3.4, Python 3.6, Python 3.7, and Python 3.8.

Python aka CPython

In addition to Python 2 and Python 3, there is more than one version of each.

Python Software Foundation logo

First of all, there are the Pythons which are maintained by the people gathered around the PSF (Python Software Foundation), a community that aims to develop, improve, expand, and popularize Python and its environment. The PSF’s president is Guido von Rossum himself, and for this reason, these Pythons are called canonical. They are also considered to be reference Pythons, as any other implementation of the language should follow all standards established by the PSF.

Guido van Rossum used the “C” programming language to implement the very first version of his language and this decision is still in force. All Pythons coming from the PSF are written in the “C” language. There are many reasons for this approach. One of them (probably the most important) is that thanks to it, Python may be easily ported and migrated to all platforms with the ability to compile and run “C” language programs (virtually all platforms have this feature, which opens up many expansion opportunities for Python).

This is why the PSF implementation is often referred to as CPython. This is the most influential Python among all the Pythons in the world.

Cython

Another Python family member is Cython.

Cython logo

Cython is one of a possible number of solutions to the most painful of Python’s traits – the lack of efficiency. Large and complex mathematical calculations may be easily coded in Python (much easier than in “C” or any other traditional language), but the resulting code execution may be extremely time-consuming.

How are these two contradictions reconciled? One solution is to write your mathematical ideas using Python, and when you’re absolutely sure that your code is correct and produces valid results, you can translate it into “C”. Certainly, “C” will run much faster than pure Python.

This is what Cython is intended to do – to automatically translate the Python code (clean and clear, but not too swift) into “C” code (complicated and talkative, but agile).

Jython

Another version of Python is called Jython.

“J” is for “Java”. Imagine a Python written in Java instead of C. This is useful, for example, if you develop large and complex systems written entirely in Java and want to add some Python flexibility to them. The traditional CPython may be difficult to integrate into such an environment, as C and Java live in completely different worlds and don’t share many common ideas.

Jython can communicate with existing Java infrastructure more effectively. This is why some projects find it useful and necessary.

Note: the current Jython implementation follows Python 2 standards. There is no Jython conforming to Python 3, so far.

Jython logo

PyPy and RPython

Take a look at the logo below. It’s a rebus. Can you solve it?

PyPy logo

It’s a logo of the PyPy – a Python within a Python. In other words, it represents a Python environment written in Python-like language named RPython (Restricted Python). It is actually a subset of Python.

The source code of PyPy is not run in the interpretation manner, but is instead translated into the C programming language and then executed separately.

This is useful because if you want to test any new feature that may be (but doesn’t have to be) introduced into mainstream Python implementation, it’s easier to check it with PyPy than with CPython. This is why PyPy is rather a tool for people developing Python than for the rest of the users.

This doesn’t make PyPy any less important or less serious than CPython, of course.

In addition, PyPy is compatible with the Python 3 language.

There are many more different Pythons in the world. You’ll find them if you look, but this course will focus on CPython.