נבנה על ידיBuilt by Ariel Yohimovich
= הוא השמה, לא שוויון= means assign, not equals= הוא השמה: Python מחשבת את מה שמימין, ומדביקה את השם שמשמאל על התוצאה.A variable is a name we give a value so we can use it again. The = sign is assignment: Python computes what's on the right and sticks the name on the left onto the result.title = "הנסיך הקטן"
pages = 96
print(title)
print(pages)
print(title, pages)title = "The Little Prince"
pages = 96
print(title)
print(pages)
print(title, pages)title = "הנסיך הקטן"
pages = 96
print(title)
print(pages)
print(title, pages)title = "The Little Prince"
pages = 96
print(title)
print(pages)
print(title, pages)הנסיך הקטן 96 הנסיך הקטן 96
The Little Prince 96 The Little Prince 96
print(author)
author = "אנטואן"print(author)
author = "Antoine"NameError: name 'author' is not defined
NameError: השם עוד לא קיים. מזיזים את ההשמה מעל השימוש.NameError: the name doesn't exist yet. Move the assignment above the use.author.Using a variable before creating it. Python reads top to bottom, and on line 1 there's no author yet.book_titlesnake_case: book_title_ ביניהן. אי אפשר להשתמש במילים שמורות כמו if או class.A variable name can contain English letters, digits and underscores, but can't start with a digit. Python uses snake_case: lowercase words joined by _. You can't use keywords like if or class.book_title = "Dune"
page_count = 412
is_finished = False
print(book_title, page_count, is_finished)book_title = "Dune"
page_count = 412
is_finished = False
print(book_title, page_count, is_finished)Dune 412 False
2nd_book = "Dune"SyntaxError: invalid decimal literal
SyntaxError: invalid decimal literal: מתחילים באות, למשל second_book.SyntaxError: invalid decimal literal: start with a letter, e.g. second_book.x = x + 1 מחשב ואז מעדכןx = x + 1 computes, then updatesx += 1 הוא קיצורx += 1 is the shortcuta, b = b, aSwap: a, b = b, apages = pages + 10 נראה מוזר במתמטיקה, אבל ב-Python זה פשוט: מחשבים את הצד הימני עם הערך הישן, ואז מעדכנים. הקיצור הוא pages += 10.You can give a variable a new value at any time. pages = pages + 10 looks odd in maths, but in Python it's simple: compute the right side with the old value, then update. The shortcut is pages += 10.read = 20
read = read + 15
read += 5
print("עמודים שקראתי:", read)
a, b = "ספר א", "ספר ב"
a, b = b, a
print(a, "|", b)read = 20
read = read + 15
read += 5
print("Pages read:", read)
a, b = "Book A", "Book B"
a, b = b, a
print(a, "|", b)read = 20
read = read + 15
read += 5
print("עמודים שקראתי:", read)
a, b = "ספר א", "ספר ב"
a, b = b, a
print(a, "|", b)read = 20
read = read + 15
read += 5
print("Pages read:", read)
a, b = "Book A", "Book B"
a, b = b, a
print(a, "|", b)עמודים שקראתי: 40 ספר ב | ספר א
Pages read: 40 Book B | Book A
+= הוא כמו להוסיף מטבעות לקופה: לא מחליפים קופה, רק משנים כמה יש בה.+= is like dropping coins in a jar: you don't replace the jar, you change how much is in it.total += 10
print(total)NameError: name 'total' is not defined
NameError: אין ערך ישן להוסיף אליו. מתחילים ב-total = 0.NameError: there's no old value to add to. Start with total = 0.+= על משתנה שעוד לא קיים.Using += on a variable that doesn't exist yet.input() מחכה להקלדהinput() waits for typingname = input("איך קוראים לך? ")
city = input("מאיפה את/ה? ")
print("שלום", name, "מ", city)name = input("What is your name? ")
city = input("Where are you from? ")
print("Hello", name, "from", city)name = input("איך קוראים לך? ")
city = input("מאיפה את/ה? ")
print("שלום", name, "מ", city)name = input("What is your name? ")
city = input("Where are you from? ")
print("Hello", name, "from", city)איך קוראים לך? Noa מאיפה את/ה? Haifa שלום Noa מ Haifa
What is your name? Noa Where are you from? Haifa Hello Noa from Haifa
input הוא כמו מלצר שמחכה ליד השולחן עד שתזמינו. כל מה שתגידו נרשם בפנקס כטקסט, גם "שתיים".input is like a waiter standing by until you order. Whatever you say is written down as text, even "two".f"...{x}..." מכניס ערכים לטקסטf"...{x}..." puts values in text{} אפשר גם חישוב{} can hold a calculation toof לפני המירכאות. כל מה שבתוך סוגריים מסולסלים {} מחושב ומוכנס לטקסט. זו הדרך הנוחה ביותר לבנות הודעות.An f-string is a string with f before the quotes. Anything inside curly braces {} is evaluated and placed in the text. It's the easiest way to build messages.{} בערך הנכון.An f-string is like a form with blanks: the text is pre-printed and Python fills each {} blank with the right value.name = "Noa"
print(f"Hi {name")SyntaxError: f-string: expecting '}'
SyntaxError על ה-f-string: לכל { צריך } מתאים.SyntaxError in the f-string: every { needs a matching }.sep קובע מה בין הערכיםsep sets what goes between valuesend קובע מה בסוף השורהend sets what ends the lineprint יש שתי הגדרות שימושיות: sep (מה מפריד בין הערכים, ברירת מחדל רווח) ו-end (מה בא בסוף, ברירת מחדל ירידת שורה \n).print has two handy settings: sep (what separates values, a space by default) and end (what comes at the end, a newline \n by default).print(19, 11, 2026, sep="/")
print("טוען", end="")
print("...", end="")
print(" מוכן!")
print("a", "b", "c", sep=" -> ")print(19, 11, 2026, sep="/")
print("Loading", end="")
print("...", end="")
print(" done!")
print("a", "b", "c", sep=" -> ")print(19, 11, 2026, sep="/")
print("טוען", end="")
print("...", end="")
print(" מוכן!")
print("a", "b", "c", sep=" -> ")print(19, 11, 2026, sep="/")
print("Loading", end="")
print("...", end="")
print(" done!")
print("a", "b", "c", sep=" -> ")19/11/2026 טוען... מוכן! a -> b -> c
19/11/2026 Loading... done! a -> b -> c
sep הוא הדבק בין לבנים, ו-end הוא מה ששמים בסוף הקיר. בלי end מיוחד, כל print מתחילה קיר חדש בשורה הבאה.sep is the mortar between bricks and end is what you put at the end of the wall. Without a special end, each print starts a new wall on the next line.pages = 96
print("Pages: " + pages)TypeError: can only concatenate str (not "int") to str
TypeError: משתמשים בפסיק (print("Pages:", pages)) או ב-f-string.TypeError: use a comma (print("Pages:", pages)) or an f-string.+ בתוך print.Trying to glue a number to a string with + inside print.= הוא השמה, לא שוויון= means assign, not equalsx = x + 1 מחשב ואז מעדכןx = x + 1 computes, then updatesinput() מחכה להקלדהinput() waits for typingf"...{x}..." מכניס ערכים לטקסטf"...{x}..." puts values in textsep קובע מה בין הערכיםsep sets what goes between valuesנבנה על ידיBuilt by Ariel Yohimovich