No history yet

Python Basics

What is Python?

Python is a popular, high-level programming language known for its clear syntax and readability. Think of it as a set of instructions you can give a computer, but written in a way that's much closer to English than to the computer's native ones and zeros. Its simplicity makes it a fantastic first language for beginners.

Lesson image

Despite its simplicity, Python is incredibly powerful. It's used everywhere: by Google for web services, by NASA for scientific programming, and by companies like Netflix and Spotify for data analysis. Whether you want to build a website, analyze data, automate repetitive tasks, or get into machine learning, Python is a great tool for the job.

A few key features make Python stand out:

  • Readable and Simple: Python's syntax is designed to be clean and uncluttered. This makes it easier to write and, just as importantly, to read code written by others.
  • Interpreted: You don't need to compile your code before running it. A program called an interpreter runs through the code line by line and executes each command directly. This makes the development process faster.
  • Huge Standard Library: Python comes with a vast collection of pre-written code, called modules, that you can use for tasks like working with dates and times, connecting to websites, and reading files. It's often called a "batteries included" language.

Getting Python on Your Machine

To start writing and running Python code, you first need to install the Python interpreter. This is the program that understands your Python scripts and tells the computer what to do. The best place to get it is from the official source.

Head over to python.org and download the latest version for your operating system, whether it's Windows, macOS, or Linux. The website usually detects your OS and suggests the correct installer.

Lesson image

On Windows, make sure to check the box that says "Add Python to PATH" during installation. This small step will make it much easier to run Python from your computer's command line.

Your Coding Environment

You can write Python code in any plain text editor, but most developers use an Integrated Development Environment, or IDE. An IDE is a software application that combines a code editor with other helpful tools, like syntax highlighting (coloring your code to make it more readable) and debugging aids to help you find errors.

Popular choices include Visual Studio Code (VS Code) and PyCharm. They are powerful and packed with features, but they can be a bit overwhelming for a beginner. Luckily, Python comes with its own simple IDE called IDLE (Integrated Development and Learning Environment). It's perfect for getting started.

Lesson image

Writing Your First Script

It's a time-honored tradition in programming to make your first program display the text "Hello, World!". Let's do that now using IDLE.

First, find and open IDLE from your applications or start menu. You'll see a window called the Python Shell. This is great for trying out single lines of code, but for a script, we want a new file. Go to File > New File.

In the new, blank window, type the following line of code:

print("Hello, World!")

This code uses the built-in print() function. A function is a named block of code that performs a specific task. The print() function's job is to display whatever you put inside the parentheses on the screen.

Now, save your file. Go to File > Save and name it something like hello.py. The .py extension is crucial; it tells the computer that this is a Python file.

To run your script, simply press the F5 key, or go to Run > Run Module. The output, Hello, World!, will appear back in the Python Shell window. You've just written and executed your first Python program!

Quiz Questions 1/5

Which of the following best describes Python?

Quiz Questions 2/5

Python is described as an 'interpreted' language. What does this mean in practice?

That's all it takes to get started. You've installed Python, learned about IDEs, and run your very first script. The next step is to learn what you can actually do with the language.