No history yet

Introduction to Python

What is Python?

Python is a popular, versatile programming language created by Guido van Rossum and first released in 1991. Its design philosophy emphasizes code readability with its notable use of significant whitespace. Think of it as a language that wants you to write clean, logical code, whether you're working on a small script or a large, complex application.

Lesson image

One of Python's biggest strengths is its simplicity. The syntax is straightforward, making it an excellent choice for beginners. But don't let its simplicity fool you. Python is powerful and used by companies like Google, Netflix, and NASA for everything from web development and data analysis to artificial intelligence and scientific computing.

Here are a few key features that make Python stand out:

  • Interpreted Language: Python code is executed line by line. This makes debugging easier because you can quickly identify where errors occur without having to compile the entire program first.
  • Vast Standard Library: Python comes with a huge collection of pre-written code, called modules, that you can use in your own programs. This means you don't have to write everything from scratch. Need to work with dates, send an email, or connect to a web server? There's likely a module for that.
  • Strong Community: Python has a massive and active global community. If you ever get stuck, chances are someone has already asked and answered your question online.

Getting Python on Your Machine

Before you can start writing Python code, you need to install it. The best place to get it is from the official website, python.org. You'll want to download the latest stable version for your operating system.

Lesson image

The installation process is slightly different depending on your system:

  • For Windows: Run the installer you downloaded. On the first screen, make sure to check the box that says "Add Python to PATH." This small step will make it much easier to run Python from the command line.
  • For macOS: Newer versions of macOS may come with Python pre-installed. However, it's often an older version. It's still a good idea to install the latest version from python.org to have access to the newest features and improvements.
  • For Linux: Most Linux distributions come with Python pre-installed. You can check your version by opening a terminal and typing python3 --version.

Your First Python Program

It's a long-standing tradition in programming to make your first program display the text "Hello, World!" on the screen. It's a simple way to confirm that your setup is working correctly. In Python, this takes just one line of code.

print("Hello, World!")

Let's break that down. print() is a built-in Python function that outputs text to the console. The text you want to print, in this case, "Hello, World!", goes inside the parentheses and is wrapped in quotes. This quoted text is called a string.

There are two main ways to run this code. You can use Python's interactive interpreter or run it from a file.

  1. Interactive Interpreter: Open your command prompt (on Windows) or terminal (on macOS/Linux) and type python3 (or just python on some systems) and press Enter. You'll see a >>> prompt. Type print("Hello, World!") and press Enter again. You'll see the output immediately.
  2. From a File: Open a plain text editor, type the code, and save the file as hello.py. The .py extension is important. Then, navigate to the folder where you saved the file in your terminal and run the command python3 hello.py. The program will execute, and you'll see "Hello, World!" printed.
Lesson image

Choosing a Code Editor

While you can write Python in any basic text editor, most developers use an Integrated Development Environment (IDE) or a dedicated code editor. These programs are designed for writing code and offer helpful features like:

  • Syntax Highlighting: Colors different parts of your code (like functions and strings) to make it easier to read.
  • Code Completion: Suggests code as you type, which can speed up your workflow.
  • Debugging Tools: Helps you find and fix errors in your code.

When you install Python, it comes with a simple IDE called IDLE. It's a great tool to start with. As you become more experienced, you might want to explore other popular options like Visual Studio Code, PyCharm, or Thonny.

For now, don't worry too much about picking the "perfect" one. The most important thing is to start writing code.

Quiz Questions 1/6

Who is the creator of the Python programming language?

Quiz Questions 2/6

Python is described as an 'interpreted' language. What does this mean for how the code is run?