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
שלום, עולם!
Python היא שפה מאוד פשוטה, ויש לה תחביר מאוד ברור. היא מעודדת את המתכנתים לתכנת ללא קוד תבניתי (מוכן מראש). הפקודה הפשוטה ביותר ב-Python היא פקודת ה-"print" - היא פשוט מדפיסה שורה (וגם כוללת שורה חדשה, בניגוד ל-C).
ישנן שתי גרסאות מרכזיות של Python, Python 2 ו-Python 3. Python 2 ו-3 די שונות זו מזו. מדריך זה משתמש ב-Python 3, כי היא תקינה מבחינה סמנטית ותומכת בתכונות חדשות יותר.
לדוגמה, הבדל אחד בין Python 2 ו-3 הוא הצהרת הprint
.
ב-Python 2, הצהרת "print" אינה פונקציה, ולכן מופעלת ללא סוגריים. עם זאת, ב-Python 3, זו פונקציה, והיא חייבת להיות מופעלת עם סוגריים.
כדי להדפיס מחרוזת ב-Python 3, פשוט כתוב:
print("This line will be printed.")
הזחה
Python משתמשת בהזחה עבור בלוקים, במקום סוגריים מסולסלים. גם כרטיסיות וגם רווחים נתמכים, אבל ההזחה הסטנדרטית דורשת קוד Python סטנדרטי להשתמש בארבעה רווחים. לדוגמה:
x = 1
if x == 1:
# הזחה של ארבעה רווחים
print("x is 1.")
תרגיל
השתמש בפונקציה "print" כדי להדפיס את השורה "Hello, World!".
print("Goodbye, World!")
print("Hello, World!")
test_output_contains("Hello, World!")
success_msg('Great job!')
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!