מה זה תכנות? התקנה וטרמינלWhat is programming? Setup & terminal
איך מחשב מבצע הוראות, התקנת Python ו-VS Code ב-Windows וב-Mac, הטרמינל, והתוכנית הראשונה עם print.
How a computer follows instructions, installing Python and VS Code on Windows and Mac, the terminal, and a first program with print.
01מה זה תכנות?What is programming?
מחשב הוא מכונה מהירה מאוד, אבל הוא לא מנחש. הוא עושה בדיוק מה שאומרים לו, ורק את זה. תוכנית היא רשימת הוראות שהמחשב מבצע לפי הסדר, ותכנות הוא כתיבת ההוראות האלה בשפה שהמחשב יודע לבצע.
A computer is a very fast machine, but it never guesses. It does exactly what it is told, and only that. A program is a list of instructions the computer carries out in order, and programming is writing those instructions in a language the computer can run.
הטקסט שאנחנו כותבים נקרא קוד. הנה התוכנית הכי קטנה שיש: שתי שורות, ובכל אחת הוראה אחת: "תציג את הטקסט הזה".
The text we write is called code. Here is about the smallest program there is: two lines, each with one instruction: "show this text".
print("שלום! זו התוכנית הראשונה שלי")
print("Python מבצעת שורה אחרי שורה")print("Hello! This is my first program")
print("Python runs one line after another")שלום! זו התוכנית הראשונה שלי Python מבצעת שורה אחרי שורה
Hello! This is my first program Python runs one line after another
צפו בהרצה צעד אחר צעדWatch it run, step by step
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
תחשבו על רובוט-שף שמקבל מתכון. הוא יבצע "שבור 2 ביצים" בדיוק, צעד אחרי צעד. אבל אם כתבתם "שבור 2 ביצם", הוא לא ינחש שהתכוונתם לביצים. הוא יעצור ויגיד "לא הבנתי". ככה בדיוק מתנהגת Python: מדויקת, צייתנית, ובלי דמיון.
Think of a robot chef following a recipe. It will "crack 2 eggs" exactly, step by step. But if you wrote "crack 2 egs", it won't guess you meant eggs. It stops and says "I didn't understand". Python behaves exactly like that: precise, obedient, and with zero imagination.
כותבים Print עם P גדולה. לבני אדם זה אותו דבר, אבל ל-Python אלה שתי מילים שונות לגמרי. Python רגישה לאותיות גדולות וקטנות.
Writing Print with a capital P. To a human it's the same, but to Python they are two completely different words. Python is case-sensitive.
Print("שלום")Print("Hello")Traceback (most recent call last):
File "/Users/you/python-course/hello.py", line 1, in <module>
Print("שלום")
^^^^^
NameError: name 'Print' is not defined. Did you mean: 'print'?Traceback (most recent call last):
File "/Users/you/python-course/hello.py", line 1, in <module>
Print("Hello")
^^^^^
NameError: name 'Print' is not defined. Did you mean: 'print'?NameError אומרת "אני לא מכירה את השם הזה". Python אפילו מנחשת למה התכוונתם: Did you mean: 'print'?. מתקנים ל-print עם p קטנה.NameError means "I don't know this name". Python even guesses what you meant: Did you mean: 'print'?. Fix it to lowercase print.צפו איפה זה נשברWatch where it breaks
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
02למה דווקא Python?Why Python?
יש מאות שפות תכנות. Python היא אחת הפופולריות בעולם, ומסיבה טובה: הקוד שלה נראה כמעט כמו אנגלית פשוטה, ואפשר לבנות איתה כמעט הכול.
There are hundreds of programming languages. Python is one of the most popular in the world, for good reason: its code reads almost like plain English, and you can build almost anything with it.
| תחוםField | מה עושים עם PythonWhat Python does there | איפה בקורסWhere in the course |
|---|---|---|
| אוטומציהAutomation | משימות משעממות שהמחשב עושה במקומכםBoring tasks the computer does for you | מפגש 28Session 28 |
| נתוניםData | טבלאות, סטטיסטיקה וגרפיםTables, statistics and charts | מפגשים 24-25Sessions 24-25 |
| אתרים ו-APIWeb & APIs | שרתים שאתרים ואפליקציות מדברים איתםServers that sites and apps talk to | מפגש 29Session 29 |
| AIAI | עבודה עם מודלי שפהWorking with language models | מפגשים 32-33Sessions 32-33 |
| משחקיםGames | משחקים דו-ממדיים עם Pygame2D games with Pygame | חלק 7Part 7 |
כשמתקינים "Python", מתקינים בעצם מפרש: תוכנה שקוראת את הקוד שלכם ומבצעת אותו, שורה אחרי שורה.
When you "install Python", you actually install an interpreter: a program that reads your code and runs it, line after line.
המפרש הוא כמו מתורגמן סימולטני: הוא שומע משפט אחד, מתרגם אותו לשפה שהמחשב מבין, והמחשב מבצע. ואז המשפט הבא.
The interpreter is like a simultaneous interpreter at a conference: it hears one sentence, translates it into the computer's language, the computer acts. Then the next sentence.
עוד דבר חשוב: מירכאות משנות הכול. מה שבתוך מירכאות הוא טקסט (מחרוזת), ו-Python מציגה אותו כמו שהוא. מה שבלי מירכאות, Python מחשבת.
One more key thing: quotes change everything. Whatever is inside quotes is text (a string), and Python shows it as is. Without quotes, Python calculates.
print(2 + 3)
print("2 + 3")5 2 + 3
צפו בהרצה צעד אחר צעדWatch it run, step by step
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
משאירים חישוב באמצע. ל-Python חסר משהו אחרי ה-+, אז היא לא יכולה להבין את השורה בכלל.
Leaving a calculation half-written. Python is missing something after +, so it can't understand the line at all.
print(2 +) File "/Users/you/python-course/quotes.py", line 1
print(2 +)
^
SyntaxError: invalid syntaxSyntaxError היא שגיאת תחביר: השורה לא כתובה לפי חוקי השפה. החץ ^ מצביע בערך למקום שבו Python הסתבכה. משלימים את החישוב: print(2 + 3).SyntaxError is a syntax error: the line doesn't follow the language rules. The ^ points roughly to where Python got confused. Complete the calculation: print(2 + 3).03התקנת Python (Windows ו-Mac)Installing Python (Windows and Mac)
התקנה נעשית פעם אחת. מורידים מהאתר הרשמי python.org את הגרסה האחרונה (3.12 ומעלה), ומתקינים. יש הבדל קטן אבל חשוב בין Windows ל-Mac, אז קראו את החלק שלכם.
Installation happens once. Download the latest version (3.12 or newer) from the official site python.org and install it. There is a small but important difference between Windows and Mac, so read your part.
WindowsWindows
- מריצים את קובץ ההתקנה שהורד.Run the installer you downloaded.
- חשוב מאוד: מסמנים בתחתית החלון את התיבה Add python.exe to PATH.Very important: at the bottom of the window, tick Add python.exe to PATH.
- לוחצים Install Now ומחכים.Click Install Now and wait.
- פותחים PowerShell (מחפשים "PowerShell" בתפריט התחל) ובודקים:Open PowerShell (search "PowerShell" in the Start menu) and check:
python --versionPython 3.13.18
MacMac
- פותחים את קובץ ה-.pkg שהורד ומאשרים את השלבים.Open the downloaded .pkg file and go through the steps.
- בסוף ההתקנה נפתחת תיקייה. אפשר ללחוץ פעמיים על Install Certificates.command (עוזר בהמשך לגישה לאינטרנט מ-Python).A folder opens at the end. You can double-click Install Certificates.command (it helps later when Python talks to the internet).
- פותחים את Terminal (Cmd+Space ומקלידים Terminal) ובודקים. שימו לב: ב-Mac הפקודה היא
python3.Open Terminal (Cmd+Space and type Terminal) and check. Note: on a Mac the command ispython3.
python3 --versionPython 3.13.18
המספר אצלכם יכול להיות קצת שונה. כל גרסה 3.12 ומעלה מתאימה לקורס.
Your number may be slightly different. Any version 3.12 or newer works for this course.
ב-Windows שכחו לסמן את Add to PATH. הטרמינל לא יודע איפה Python נמצאת, כי היא לא ב-PATH.
On Windows, forgot to tick Add to PATH. The terminal doesn't know where Python is, because it isn't on PATH.
python --versionpython : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
py --version."Not recognized" means the terminal found no program with that name. Fix: run the installer again, choose Modify or reinstall with the box ticked, then open a new PowerShell. Meanwhile, try py --version.04הטרמינל: לדבר עם המחשב בטקסטThe terminal: talking to the computer in text
הטרמינל הוא חלון שבו מקלידים פקודות במקום ללחוץ עם העכבר. זה נראה מפחיד בהתחלה, אבל צריך רק חמש-שש פקודות כדי להסתדר מצוין.
The terminal is a window where you type commands instead of clicking. It looks scary at first, but five or six commands are enough to get along great.
הטרמינל תמיד "עומד" בתיקייה אחת: התיקייה הנוכחית. הכתובת שלה נקראת נתיב.
The terminal always "stands" in one folder (directory): the current directory. Its address is called a path.
| מה רוציםWhat you want | MacMac | Windows (PowerShell)Windows (PowerShell) |
|---|---|---|
| איפה אני?Where am I? | pwd | pwd |
| מה יש כאן?What's here? | ls | dir (או ls)dir (or ls) |
| להיכנס לתיקייהGo into a folder | cd Desktop | cd Desktop |
| לעלות תיקייה אחת למעלהGo up one folder | cd .. | cd .. |
| ליצור תיקייהMake a folder | mkdir python-course | mkdir python-course |
| לנקות את המסךClear the screen | clear | cls |
הטרמינל הוא כמו לנווט בבניין עם עיניים עצומות ומישהו שעונה לכם: pwd = "באיזה חדר אני?", ls = "מה יש בחדר?", cd = "תיכנס לדלת הזו", cd .. = "צא החוצה למסדרון".
The terminal is like moving through a building with your eyes closed and a helper who answers: pwd = "which room am I in?", ls = "what's in this room?", cd = "go through this door", cd .. = "step back out to the hallway".
נסו עכשיו בסימולטור. הוא מתנהג כמו טרמינל אמיתי (ב-Mac או ב-Windows), אבל הכול קורה בתוך העמוד. בצעו את המשימות שמתחת:
Try it now in the simulator. It behaves like a real terminal (Mac or Windows), but everything happens inside this page. Complete the tasks below it:
- גלו איפה אתם עם
pwdFind out where you are withpwd - צרו תיקייה:
mkdir python-courseMake a folder:mkdir python-course - היכנסו אליה:
cd python-courseGo into it:cd python-course - צרו קובץ:
echo 'print("Hi")' > hello.pyCreate a file:echo 'print("Hi")' > hello.py - הריצו אותו:
python3 hello.py(ב-Windows:python hello.py)Run it:python3 hello.py(Windows:python hello.py)
מריצים קובץ מהתיקייה הלא נכונה, או עם שגיאת כתיב בשם הקובץ. Python מחפשת את הקובץ רק בתיקייה הנוכחית.
Running a file from the wrong folder, or with a typo in its name. Python only looks for the file in the current directory.
python3 helo.pypython3: can't open file '/Users/you/python-course/helo.py': [Errno 2] No such file or directory
No such file or directory = "אין קובץ כזה כאן". בודקים שני דברים: האם אני בתיקייה הנכונה (pwd, ls), והאם השם כתוב בדיוק נכון.No such file or directory = "there is no such file here". Check two things: am I in the right folder (pwd, ls), and is the name spelled exactly right.05VS Code והקובץ הראשוןVS Code and the first file
עורך קוד הוא המקום שבו כותבים קוד בנוחות. בקורס משתמשים ב-VS Code: חינמי, עובד בכל מערכת, ויש לו תוסף מצוין ל-Python.
A code editor is where you write code comfortably. In this course we use VS Code: free, runs everywhere, and has an excellent Python extension.
- מורידים ומתקינים מ-code.visualstudio.com.Download and install from code.visualstudio.com.
- פותחים את חלון התוספים (Ctrl+Shift+X, ב-Mac Cmd+Shift+X), מחפשים Python של Microsoft ומתקינים.Open Extensions (Ctrl+Shift+X, on Mac Cmd+Shift+X), search Python by Microsoft and install it.
- File → Open Folder ובוחרים את התיקייה
python-course.File → Open Folder and choose thepython-coursefolder. - יוצרים קובץ חדש בשם
hello.py. הסיומת .py אומרת "זה קוד Python".Create a new file namedhello.py. The .py ending says "this is Python code". - כותבים קוד, שומרים (Ctrl+S), ולוחצים על ▶ בפינה העליונה. הפלט מופיע בחלונית הטרמינל למטה.Write code, save (Ctrl+S), and click ▶ in the top corner. The output appears in the terminal panel at the bottom.
print("שלום מ-VS Code!")
print("הקובץ הזה הוא סקריפט")
print("כל הכבוד לי!")print("Hello from VS Code!")
print("This file is a script")
print("Well done, me!")שלום מ-VS Code! הקובץ הזה הוא סקריפט כל הכבוד לי!
Hello from VS Code! This file is a script Well done, me!
צפו בהרצה צעד אחר צעדWatch it run, step by step
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
קובץ כזה, שמריצים מההתחלה עד הסוף, נקרא סקריפט. כשלוחצים ▶, VS Code בעצם מקליד בשבילכם בטרמינל את הפקודה python3 hello.py.
A file like this, run from start to finish, is called a script. When you click ▶, VS Code really just types python3 hello.py in the terminal for you.
VS Code הוא כמו מטבח מאובזר: אפשר לבשל גם על גזייה בשטח (Notepad + טרמינל), אבל עם כיריים, סכינים חדים ותבלינים בהישג יד, הכול מהיר ונעים יותר.
VS Code is like a well-equipped kitchen: you could cook on a camping stove (Notepad + terminal), but with a proper stove, sharp knives and spices in reach, everything is faster and nicer.
שוכחים לשמור לפני הרצה, או שומרים בשם hello.py.txt. רואים את הנקודה הלבנה ליד שם הקובץ בלשונית? היא אומרת "לא נשמר".
Forgetting to save before running, or saving as hello.py.txt. See the white dot next to the file name in the tab? It means "not saved".
python3 hello.pypython3: can't open file '/Users/you/python-course/hello.py': [Errno 2] No such file or directory
06print: מדברים עם המסךprint: talking to the screen
print היא פונקציה: פעולה עם שם, שמפעילים בעזרת סוגריים. מה שבתוך הסוגריים נשלח לפלט. אפשר לתת לה טקסט, מספרים, חישובים, וכמה דברים ביחד מופרדים בפסיקים. כל print מתחילה שורה חדשה, ו-print() ריקה מדפיסה שורה ריקה.
print is a function: a named action you run with parentheses. Whatever is inside the parentheses goes to the output. You can give it text, numbers, calculations, and several things separated by commas. Each print starts a new line, and an empty print() prints a blank line.
מה קורה עכשיוWhat happens now
מסך הפלטOutput screen
שוכחים לסגור מירכאות. Python לא יודעת איפה הטקסט נגמר.
Forgetting to close the quotes. Python doesn't know where the text ends.
print("שלום)print("Hello) File "/Users/you/python-course/hello.py", line 1
print("שלום)
^
SyntaxError: unterminated string literal (detected at line 1) File "/Users/you/python-course/hello.py", line 1
print("Hello)
^
SyntaxError: unterminated string literal (detected at line 1)unterminated string literal = "מחרוזת שלא נסגרה". סופרים מירכאות: תמיד צריכות להיות שתיים, אחת בהתחלה ואחת בסוף.unterminated string literal = "a string that was never closed". Count the quotes: there must always be two, one at the start and one at the end.אפשר להשתמש במירכאות כפולות "..." או בודדות '...'. רק שיהיו מאותו סוג בהתחלה ובסוף.
You can use double quotes "..." or single quotes '...'. Just use the same kind at the start and the end.
כמה print אחד אחרי השני יוצרים ציור קטן. כל print הוא שורה חדשה על המסך.
A few prints in a row make a small picture. Each print is a new line on the screen.
print("*********")
print("* Hello! *")
print("*********")
print("Made by me")********* * Hello! * ********* Made by me
צפו בהרצה צעד אחר צעדWatch it run, step by step
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
07Python כמחשבוןPython as a calculator
Python יודעת לחשב. הסימנים שמבצעים פעולות נקראים אופרטורים. סדר הפעולות כמו בבית הספר: כפל וחילוק לפני חיבור וחיסור, וסוגריים קודם לכול.
Python can calculate. The symbols that do operations are called operators. The order is like in school: multiply and divide before add and subtract, and parentheses first.
print(7 + 3) # חיבור
print(7 - 3) # חיסור
print(7 * 3) # כפל
print(7 / 2) # חילוק
print(7 // 2) # חילוק שלם
print(7 % 2) # שארית
print(2 ** 10) # חזקה
print(2 + 3 * 4)
print((2 + 3) * 4)print(7 + 3) # add
print(7 - 3) # subtract
print(7 * 3) # multiply
print(7 / 2) # divide
print(7 // 2) # whole division
print(7 % 2) # remainder
print(2 ** 10) # power
print(2 + 3 * 4)
print((2 + 3) * 4)10 4 21 3.5 3 1 1024 14 20
10 4 21 3.5 3 1 1024 14 20
צפו בהרצה צעד אחר צעדWatch it run, step by step
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
שימו לב: 7 / 2 נותן 3.5, מספר עשרוני, ו-7 // 2 נותן 3, מספר שלם. על סוגי מספרים נדבר לעומק במפגש 3.
Notice: 7 / 2 gives 3.5, a float, and 7 // 2 gives 3, an integer (int). We go deep into number types in session 3.
// ו-% הם כמו חלוקת 7 עוגיות בין 2 ילדים: כל ילד מקבל 3 עוגיות (7 // 2), ונשארת עוגייה אחת (7 % 2).
// and % are like sharing 7 cookies between 2 kids: each kid gets 3 cookies (7 // 2), and 1 cookie is left over (7 % 2).
מחלקים באפס. גם במתמטיקה אי אפשר, ו-Python עוצרת את התוכנית.
Dividing by zero. You can't do that in math either, and Python stops the program.
print(10 / 0)Traceback (most recent call last):
File "/Users/you/python-course/calc.py", line 1, in <module>
print(10 / 0)
~~~^~~
ZeroDivisionError: division by zeroZeroDivisionError: division by zero = "חילוק באפס". מתקנים את המספר. בהמשך הקורס (מפגש 11) נלמד איך לתפוס שגיאה כזו בלי שהתוכנית תיפול.ZeroDivisionError: division by zero means exactly that. Fix the number. Later (session 11) we learn to catch such errors without crashing.צפו איפה זה נשברWatch where it breaks
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
Python היא מחשבון: פיצה ב-84 שקלים לשלושה חברים.
Python is a calculator: an 84-shekel pizza for three friends.
print(84 / 3)
print(84 // 3)
print(2 * 3 + 1)
print(2 * (3 + 1))28.0 28 7 8
צפו בהרצה צעד אחר צעדWatch it run, step by step
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
08הערות, סדר והזחהComments, order and indentation
כל מה שאחרי # הוא הערה: Python מתעלמת ממנו לגמרי. הערות הן פתקים לבני אדם, כולל לעצמכם בעוד חודש. Python מבצעת את השורות לפי הסדר, מלמעלה למטה, ולכן הסדר בקובץ הוא הסדר בפלט.
Everything after # is a comment: Python ignores it completely. Comments are notes for humans, including yourself a month from now. Python runs the lines in order, top to bottom, so the order in the file is the order in the output.
# התוכנית מדפיסה כרטיס ביקור
print("דנה כהן")
print("מפתחת Python (מתחילה)")
# print("השורה הזו לא תודפס")
print("dana@example.com") # הערה בסוף שורה# This program prints a business card
print("Dana Cohen")
print("Python developer (beginner)")
# print("This line will not print")
print("dana@example.com") # a comment at the end of a lineדנה כהן מפתחת Python (מתחילה) dana@example.com
Dana Cohen Python developer (beginner) dana@example.com
צפו בהרצה צעד אחר צעדWatch it run, step by step
מה קורה עכשיוWhat happens now
הקופסאות (משתנים)The boxes (variables)
מסך הפלטOutput screen
טריק שימושי: כדי "לכבות" שורה בלי למחוק אותה, שמים לפניה #. ב-VS Code: Ctrl+/ (ב-Mac Cmd+/).
Handy trick: to "switch off" a line without deleting it, put # in front. In VS Code: Ctrl+/ (Mac: Cmd+/).
מתחילים שורה ברווח. ב-Python לרווחים בתחילת שורה, הזחה, יש משמעות (נלמד עליה במפגש 5), ולכן רווח "סתם" הוא שגיאה.
Starting a line with a space. In Python, spaces at the start of a line, indentation, have meaning (session 5), so a "random" space is an error.
print("שורה ראשונה")
print("שורה שנייה")print("First line")
print("Second line") File "/Users/you/python-course/card.py", line 2
print("שורה שנייה")
IndentationError: unexpected indent File "/Users/you/python-course/card.py", line 2
print("Second line")
IndentationError: unexpected indentIndentationError: unexpected indent = "הזחה שלא ציפיתי לה". מוחקים את הרווח בתחילת שורה 2.IndentationError: unexpected indent = "an indent I didn't expect". Delete the space at the start of line 2.09מצב אינטראקטיבי (REPL) מול סקריפטInteractive mode (REPL) vs a script
אם מקלידים בטרמינל רק python3 (או python ב-Windows), נכנסים למצב אינטראקטיבי. Python מציגה >>> ומחכה לשורה אחת. מקלידים, לוחצים Enter, ורואים תוצאה מיד. יוצאים עם exit().
Typing just python3 in the terminal (python on Windows) enters interactive mode. Python shows >>> and waits for one line. Type, press Enter, see the result immediately. Leave with exit().
python3
>>> 2 + 2
4
>>> print("Hi")
Hi
>>> exit()| REPL (>>>)REPL (>>>) | סקריפט (קובץ .py)Script (.py file) | |
|---|---|---|
| למה זה טובGood for | ניסוי קטן ומהירA quick small experiment | תוכנית שרוצים לשמור ולהריץ שובA program you keep and run again |
| נשמר?Saved? | לא, נעלם כשסוגריםNo, gone when you close it | כן, בקובץYes, in the file |
| איך מריציםHow to run | python3 ואז שורה אחרי שורהpython3, then line by line | python3 hello.py או ▶python3 hello.py or ▶ |
ה-REPL הוא כמו מחשבון כיס: מהיר ונוח, אבל שום דבר לא נשמר. סקריפט הוא כמו מתכון כתוב: אפשר לבשל אותו שוב מחר.
The REPL is like a pocket calculator: quick and handy, but nothing is saved. A script is like a written recipe: you can cook it again tomorrow.
מעתיקים מהאינטרנט קוד עם >>> לתוך קובץ. ה->>> הוא חלק מהתצוגה של ה-REPL, לא חלק מהקוד.
Copying code from the internet with >>> into a file. The >>> is part of the REPL display, not part of the code.
>>> print("Hi") File "/Users/you/python-course/hello.py", line 1
>>> print("Hi")
^^
SyntaxError: invalid syntax>>> כקוד, ולכן invalid syntax. מוחקים את >>> ואת הרווח שאחריו.Python doesn't know >>> as code, hence invalid syntax. Delete the >>> and the space after it.10איך קוראים הודעת שגיאהHow to read an error message
שגיאות הן לא כישלון. הן Python שמנסה לעזור. כשתוכנית נופלת, Python מדפיסה דוח שנקרא Traceback. קוראים אותו מלמטה למעלה: השורה האחרונה אומרת מה קרה, ומעליה כתוב איפה (קובץ ומספר שורה).
Errors are not failure. They are Python trying to help. When a program crashes, Python prints a report called a traceback. Read it bottom to top: the last line says what happened, and above it is where (file and line number).
print("לפני השגיאה")
print("התוצאה:", 10 / 0)
print("השורה הזו כבר לא תרוץ")print("Before the error")
print("Result:", 10 / 0)
print("This line will never run")לפני השגיאה
Traceback (most recent call last):
File "/Users/you/python-course/crash.py", line 2, in <module>
print("התוצאה:", 10 / 0)
~~~^~~
ZeroDivisionError: division by zeroBefore the error
Traceback (most recent call last):
File "/Users/you/python-course/crash.py", line 2, in <module>
print("Result:", 10 / 0)
~~~^~~
ZeroDivisionError: division by zero| חלק בהודעהPart of the message | מה הוא אומרWhat it says |
|---|---|
File ".../crash.py", line 2File ".../crash.py", line 2 | איפה: הקובץ והשורהWhere: the file and the line |
השורה עם ~~^~~The line with ~~^~~ | הקוד עצמו, והסימון מראה את החלק הבעייתיThe code itself, with the problem part marked |
ZeroDivisionErrorZeroDivisionError | מה: סוג השגיאהWhat: the error type |
division by zerodivision by zero | הסבר קצר באנגליתA short explanation |
שימו לב: השורה הראשונה כן הודפסה. Python ביצעה את שורה 1, נפלה בשורה 2, ושורה 3 לא רצה בכלל. טעות בקוד נקראת באג, ומציאת באגים היא חלק רגיל לגמרי מהעבודה, גם של מתכנתים ותיקים.
Notice: the first line was printed. Python ran line 1, crashed on line 2, and line 3 never ran. A mistake in code is called a bug, and finding bugs is a perfectly normal part of the job, even for experienced developers.
שיטת 3 השאלות לכל שגיאה: (1) מה הסוג? (2) איפה (שורה)? (3) מה שונה בשורה הזו ממה שהתכוונתי? במפגש 11 נעמיק עם Traceback ארוכים.
The 3-question method for any error: (1) what type? (2) where (line)? (3) what is different on that line from what I meant? In session 11 we go deep into long tracebacks.
סיימתם את ההרצאה!Lecture complete!
עכשיו המצגת לחזרה מהירה, או ישר לתרגול.
Next: the slides for a quick review, or straight to practice.