Setting Up and Your First Program
Setting Up and Your First Program
Getting Started with Python
Python is a beginner-friendly programming language known for its clear, readable syntax. Before you can write your first program, you need to install Python on your computer and set up a development environment where you can write and run code.
Installing Python
The first step is to download Python from the official website at python.org. Navigate to the Downloads section and select the version appropriate for your operating system—Windows, macOS, or Linux. As of this lesson, Python 3.x is the current standard version you should use.
During installation on Windows, make sure to check the box that says "Add Python to PATH." This allows you to run Python from any location on your computer. On macOS and Linux, Python is often pre-installed, but you may need to update it to the latest version.
After installation, verify that Python is correctly installed by opening your command prompt (Windows) or terminal (macOS/Linux) and typing:
python --version
If Python is properly installed, you'll see the version number displayed.
Choosing Your Development Environment
You have several options for writing Python code:
- Text Editor: A simple editor like Notepad++ or VS Code works well for beginners. VS Code is particularly popular because it's free and has excellent Python support.
- Integrated Development Environment (IDE): Tools like PyCharm Community Edition or IDLE (included with Python) provide built-in features for writing, debugging, and running code.
- Online Platforms: Websites like Repl.it or Google Colab let you write and run Python without any installation.
For beginners, IDLE or VS Code provides a good balance of simplicity and functionality.
Writing Your First Program
Let's create your first Python program. Open your chosen editor and type the following:
print("Hello, World!")
This single line demonstrates several important concepts. The print() function displays text on your screen. The text inside the parentheses, called a string, must be enclosed in quotes.
Save this file with a .py extension (for example, hello.py). Then run it by opening your terminal, navigating to the file's location, and typing:
python hello.py
You should see Hello, World! displayed on your screen. Congratulations—you've written and executed your first Python program!
Understanding Basic Syntax
Python code follows specific rules called syntax. Notice that:
- Functions like
print()are followed by parentheses - Strings must be in quotes (single or double)
- Python reads code from top to bottom, line by line
- Indentation (spacing at the beginning of lines) is important in Python and affects how code runs
Next Steps
Now that your environment is set up, you're ready to explore variables, data types, and more complex programs. Practice writing simple programs using the print function to display different messages. This foundation will prepare you for the more advanced programming concepts ahead.