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.")

Exercise

Використовуйте функцію "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!

Next Tutorial Take the Test
Copyright © learnpython.org. Read our Terms of Use and Privacy Policy