Your first Python program
20 min ยท Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)A Python program is a series of statements that execute from top to bottom. Write a simple program, save it as hello.py and run it in VS Code or in the terminal.
Write the code
A statement is one instruction that Python runs. print("Hello, Python!") is a statement that shows text on the screen.
In Python, printing a greeting takes only one line of code.
print("Hello, Python!")There is no boilerplate: no class wrapper, no curly braces, and no trailing semicolon. Python starts executing directly from the first statement.
Run in terminal or VS Code
To run in the terminal, navigate to your practice folder and execute Python with your file name.
python hello.pyHello, Python!
In VS Code, simply open hello.py and click the Run play button in the top right corner. The output appears in the integrated terminal below.
Common beginner mistakes
Beginners often encounter clear error messages that show the line number and mistake.
- Missing quotation mark:
print("Hello)causesSyntaxError: unterminated string literal. - Typo in function name:
Print("Hello")with capital P causesNameError: name 'Print' is not definedbecause Python is case-sensitive. - Missing parentheses: In Python 3,
printrequires parenthesesprint(...).
Example
print("Welcome to MentorNxt")print("Day 1 of Python")Welcome to MentorNxt Day 1 of Python
What this code does
- Statements execute sequentially from top to bottom.
- First,
Welcome to MentorNxtprints to the console. - Next,
Day 1 of Pythonprints on a new line.
What's next
You finished the preview of Getting Started
Python Programming has 21 sections, 110 modules and 609 lessons. An account opens every lesson and saves your progress.
Next step
Check your understanding
5 quick questions