נבנה על ידיBuilt by Ariel Yohimovich
int שלם, float עשרוניint whole, float decimalstr טקסט, bool אמת/שקרstr text, bool true/falsetype(x) מגלה את הטיפוסtype(x) reveals the typetype מראה את הטיפוס.Every value in Python has a type. The type decides what you can do with it: numbers can be divided, text can be uppercased. The type function shows the type.print(type(42))
print(type(3.5))
print(type("42"))
print(type(True))
print(7 / 2, type(7 / 2))print(type(42))
print(type(3.5))
print(type("42"))
print(type(True))
print(7 / 2, type(7 / 2))<class 'int'> <class 'float'> <class 'str'> <class 'bool'> 3.5 <class 'float'>
print("5" + 5)TypeError: can only concatenate str (not "int") to str
TypeError: ממירים קודם: int("5") + 5 נותן 10, "5" + str(5) נותן "55".TypeError: convert first: int("5") + 5 gives 10, "5" + str(5) gives "55".int("7") → 7int("7") → 7float("2.5") → 2.5float("2.5") → 2.5str(7) → "7"str(7) → "7"input מחזירה למספר, כדי שאפשר יהיה לחשב איתו.Type conversion makes a new value of a different type. Most useful: turning what input returns into a number so you can calculate with it.age = int(input("גיל: "))
print(f"בשנה הבאה תהיו בני {age + 1}")
price = float("19.90")
print(price * 2)
print(str(2026) + "!")age = int(input("Age: "))
print(f"Next year you will be {age + 1}")
price = float("19.90")
print(price * 2)
print(str(2026) + "!")age = int(input("גיל: "))
print(f"בשנה הבאה תהיו בני {age + 1}")
price = float("19.90")
print(price * 2)
print(str(2026) + "!")age = int(input("Age: "))
print(f"Next year you will be {age + 1}")
price = float("19.90")
print(price * 2)
print(str(2026) + "!")גיל: 30 בשנה הבאה תהיו בני 31 39.8 2026!
Age: 30 Next year you will be 31 39.8 2026!
pages = int("96 pages")ValueError: invalid literal for int() with base 10: '96 pages'
ValueError: int מקבלת רק ספרות. בהמשך (מפגש 11) נתפוס שגיאה כזו בלי שהתוכנית תיפול.ValueError: int accepts digits only. Later (session 11) we catch this without crashing.True/FalseComparisons return True/False== שווה, != שונה== equal, != not equalbool(0) הוא Falsebool(0) is FalseTrue ו-False. השוואות כמו > או == מחזירות ערך כזה. במפגש 5 נשתמש בהם כדי לקבל החלטות.A boolean (bool) type has just two values: True and False. Comparisons like > or == return one. In session 5 we use them to make decisions.done = trueNameError: name 'true' is not defined. Did you mean: 'True'?
NameError: true הוא סתם שם לא מוכר. כותבים True.NameError: true is just an unknown name. Write True.true באות קטנה. ב-Python זה True עם T גדולה.Writing true in lowercase. In Python it's True with a capital T.round(x, 2) לשתי ספרותround(x, 2) to two places0.1 + 0.2 הוא 0.300000000000000040.1 + 0.2 is 0.30000000000000004f"{x:.2f}"For display: f"{x:.2f}"round או עם עיצוב ב-f-string.Computers store decimals in base 2, so some aren't perfectly exact. It's not a Python bug; every computer works this way. For display, round with round or format in an f-string.print(0.1 + 0.2)
print(round(0.1 + 0.2, 2))
print(round(2.675, 2))
price = 19.9
print(f"{price:.2f} ₪")
print(round(7.5), round(8.5))print(0.1 + 0.2)
print(round(0.1 + 0.2, 2))
print(round(2.675, 2))
price = 19.9
print(f"{price:.2f} ₪")
print(round(7.5), round(8.5))0.30000000000000004 0.3 2.67 19.90 ₪ 8 8
price = float("19,90")ValueError: could not convert string to float: '19,90'
ValueError: משתמשים בנקודה: "19.90". אם הקלט מגיע עם פסיק: text.replace(",", ".").ValueError: use a dot: "19.90". If input comes with a comma: text.replace(",", ".").import math טוען מודולimport math loads a modulemath.sqrt, math.pi, math.ceilmath.sqrt, math.pi, math.ceilabs, min, max מובנותabs, min, max are built inimport math נותן שורשים, פאי, עיגול למעלה ולמטה ועוד. פונקציות כמו abs, min ו-max מובנות ולא צריך לייבא אותן.A module is a ready toolbox. import math gives square roots, pi, rounding up and down, and more. Functions like abs, min and max are built in and need no import.import הוא כמו להוציא ארגז כלים מהמחסן. הכלים היו שם תמיד, רק צריך להביא אותם לשולחן.import is like fetching a toolbox from the shed. The tools were always there; you just bring them to the table.print(math.sqrt(16))NameError: name 'math' is not defined. Did you forget to import 'math'?
NameError: name 'math' is not defined: מוסיפים import math בראש הקובץ.NameError: name 'math' is not defined: add import math at the top of the file.math בלי import.Using math without import.** לפני * לפני +** before * before +// ו-% לחלוקה ושארית// and % for division and remainderminutes = 135
hours = minutes // 60
rest = minutes % 60
print(f"{hours}:{rest:02d}")
print(2 + 3 * 2 ** 2)
print((2 + 3) * 2 ** 2)minutes = 135
hours = minutes // 60
rest = minutes % 60
print(f"{hours}:{rest:02d}")
print(2 + 3 * 2 ** 2)
print((2 + 3) * 2 ** 2)2:15 14 20
total = (2 + 3 * (4 - 1)
print(total)SyntaxError: '(' was never closedSyntaxError: '(' was never closed: סופרים סוגריים פותחים וסוגרים.SyntaxError: '(' was never closed: count opening and closing brackets.int שלם, float עשרוניint whole, float decimalstr טקסט, bool אמת/שקרstr text, bool true/falsetype(x) מגלה את הטיפוסtype(x) reveals the typeint("7") → 7int("7") → 7int שלם, float עשרוניint whole, float decimalint("7") → 7int("7") → 7True/FalseComparisons return True/Falseround(x, 2) לשתי ספרותround(x, 2) to two placesimport math טוען מודולimport math loads a module** לפני * לפני +** before * before +נבנה על ידיBuilt by Ariel Yohimovich