No history yet

Introduction to Python

What is Python?

Python is a programming language known for its clear, readable syntax. Think of it less like a cryptic code and more like a set of precise instructions written in a style that resembles English. It was created in the late 1980s by Guido van Rossum with a core philosophy of simplicity and readability.

This focus on simplicity doesn't mean it's not powerful. Python is incredibly versatile and used across many industries. Web developers use it to build the back-end of websites, data scientists use it to analyze information and create machine learning models, and system administrators use it to automate repetitive tasks. From building games to analyzing financial markets, Python is a tool for all sorts of problem-solving.

Lesson image

Setting Up Your Workspace

To start writing Python, you need two things: the Python interpreter itself, which runs your code, and a place to write that code. Let's get both set up.

First, you need to install Python on your computer. The official source for this is the Python Software Foundation's website, python.org. Head there and download the latest version for your operating system. During installation on Windows, make sure to check the box that says "Add Python to PATH." This small step makes it much easier to run Python from your computer's command line.

Lesson image

Next, you need a code editor or an Integrated Development Environment (IDE). An IDE is a program designed to make coding easier. It usually includes a text editor with features like syntax highlighting (coloring your code to make it easier to read) and tools for running and debugging your programs.

Two popular choices for beginners are Visual Studio Code (VS Code) and PyCharm.

  • VS Code is a free, lightweight, and highly customizable code editor from Microsoft. With the addition of a Python extension, it becomes a powerful environment for Python development.
  • PyCharm is an IDE made specifically for Python. It has many powerful features built-in and offers a free Community Edition that is perfect for learning.

Either one is a great choice. Install one of them to get started.

Lesson image

Your First Program

It's a long-standing tradition in programming to make your first program in a new language simply display the phrase "Hello, World!" on the screen. It's a simple way to confirm that your setup is working correctly and to see the basic syntax of the language.

Here's how you do it in Python. Open your IDE, create a new file, and save it as hello.py. The .py extension is important, as it tells your computer that this is a Python file. In that file, type the following single line of code:

print("Hello, World!")

That's it. This line tells Python to use the built-in print function to display the text inside the parentheses. The text itself, called a string, is enclosed in double quotes.

Now, let's run it. Most IDEs have a "Run" button (often a green triangle) that will execute the code in the current file. You can also run it from your computer's terminal or command prompt. Navigate to the directory where you saved hello.py and type:

python hello.py

If everything is set up correctly, you'll see this output:

Hello, World!

Congratulations! You've just written and executed your first Python program.

Quiz Questions 1/5

What is the core philosophy that guided the design of the Python programming language?

Quiz Questions 2/5

Which of the following lines of code is the correct way to display the text "Hello, World!" on the screen in Python?