Jan 6th, 2023
![Python1](photos/1_6_23.webp)
Welcome to my new Python3 intro course! Python is a fantastic language to learn for beginners, as it's very versatile, has a comprehensive standard library with a wide range of downloadable modules, a user-friendly syntax, and has a wide range of applications. From system administrators using the standard library, to data scientists using pandas and numpy, to machine learning engineers using TensorFlow, to web developers using Django, to first-time coders, Python might be the perfect language for you to learn.
In this first lesson, we will cover setting up your Python environment so that it works from the command line.
To get started, you'll need to make sure you have Python3 downloaded on your machine.
If you're using macOS, you should already have it installed, but you can also download the latest version from python.org.
On Linux, you can download Python3 via your package manager (e.g. sudo apt install Python3
on Debian).
On Windows, you can download Python3 from the official website and make sure to click the option to add Python to your system PATH.
Once you have Python3 installed, you'll want to ensure it's up and running properly.
Open up your terminal or command line and type python3
.
You should see a response like this: >>>
This is called the Python REPL (read-evaluate-print loop), which allows you to enter lines of Python code and have them evaluated.
This is useful for testing your code or doing quick calculations on your computer.
If you encounter any errors when running your code, try going through it line by line in the REPL to identify the cause.
Next, you'll need to choose a text editor to use for writing your code. There are many options available, including vim, neovim, Notepad, Sublime, Notepad++, and Emacs. In this course, we'll be using Visual Studio Code (VSC). To set up VSC for Python, create a new directory to hold your Python files and open it in VSC as your project. Then, download the Python and Pylance extensions from Microsoft from the extensions tab on the right. These tools will provide syntax highlighting, easier debugging, static type checking, and code formatting, which are all helpful for anyone starting out with Python.
Now that you have your environment set up, let's create our first Python program.
In the Explorer tab on the left, click the new file button and name it hello.py
.
Inside this file, type print("Hello World!")
.
The print()
function writes the text inside the parentheses (called the "parameter") to the console.
In this case, the parameter is a string (a series of characters enclosed in quotation marks).
To run your program, you can use the terminal in VSC by clicking the terminal tab at the top and then clicking the new terminal button.
This will open a terminal window at the bottom of the screen, inside the directory you created and opened earlier.
Type python3 hello.py
and hit enter to run the program, and "Hello World" should appear.
Congratulations, you've created and run your first Python program!
In the next lesson, we'll cover basic data types and variables in Python, and we'll create a slightly larger program that includes reading input from the user. I hope you found this lesson helpful!