Installing Python
Before we dive into the world of Python programming, it's essential to have the correct environment set up on your computer. In this sub-module, we'll cover how to install Python and some basic concepts that will help you get started with writing your first Python program.
Downloading Python
To get started, go to the official Python website ([www.python.org](http://www.python.org)) and click on the "Downloads" tab. You'll see a list of pre-built binaries for various platforms (Windows, macOS, Linux). Click on the one that matches your operating system.
For Windows users:
- Download the latest version of Python 3.x (x being the minor version number).
- Run the installer and follow the prompts to install Python.
- Make sure to select the option to add Python to your PATH during installation. This allows you to run Python from anywhere in your command line.
For macOS users:
- Download the latest version of Python 3.x (x being the minor version number).
- Open the `.dmg` file and follow the prompts to install Python.
- Make sure to select the option to add Python to your PATH during installation. This allows you to run Python from anywhere in your terminal.
For Linux users:
- Check if Python is already installed on your system by running `python --version` in your terminal. If it's not, proceed with downloading and installing the latest version of Python 3.x (x being the minor version number) from the official Python website.
- Follow the installation prompts to install Python.
Understanding the Command Line
The command line is a powerful tool for interacting with your computer and managing files. It's essential to understand basic commands and how to navigate through directories using the command line.
#### Basic Commands:
- `cd` (Change Directory): Used to navigate through directories.
+ Example: `cd Documents/Python`
- `ls` (List Files): Displays a list of files in the current directory.
+ Example: `ls -l`
- `mkdir` (Make Directory): Creates a new directory.
+ Example: `mkdir MyPythonFolder`
- `rm` (Remove): Deletes a file or directory.
+ Example: `rm myfile.txt`
#### Navigation:
- Use the `cd` command to navigate through directories. You can use absolute paths (`/path/to/directory`) or relative paths (`./subdirectory`).
- Use the `pwd` command to display the current working directory.
Writing Your First Python Program
Now that you have Python installed and understand basic command-line concepts, let's write your first Python program!
Create a new file called `hello.py` using your preferred text editor or IDE (Integrated Development Environment). Open the file and add the following code:
```python
print("Hello, World!")
```
This is a simple Python program that prints "Hello, World!" to the console. Save the file and run it using the command line by typing `python hello.py`.
Understanding the Code:
- The `print()` function is used to output text to the console.
- The string `"Hello, World!"` is passed as an argument to the `print()` function.
- When you run the program, Python will execute the code and print the specified message.
This is just a starting point, but it's essential to understand these basic concepts before moving forward with your Python journey. In the next sub-module, we'll cover setting up a development environment, writing more complex programs, and exploring some of the built-in features of Python!