No history yet

Python Basics

What is Python?

Python is a high-level, general-purpose programming language. Let's break that down. "High-level" means it's designed to be easy for humans to read and write. Its syntax is clean and straightforward, which is why it's often recommended for beginners. You write code that looks a lot like plain English.

"General-purpose" means you can use it for almost anything. People build websites, analyze data, create video games, and automate repetitive tasks all with Python. Its versatility is one of its biggest strengths.

Python's core philosophy is that code should be readable and simple. If you have a choice between a clever, complex solution and a clear, straightforward one, Python programmers will almost always choose clarity.

Getting Set Up

To start programming in Python, you need two main things: the Python interpreter and a text editor.

The interpreter is the program that understands and runs your Python code. You can download it for free from the official website, python.org. The installation process is typically a simple wizard you can click through.

Lesson image

A text editor is where you'll write your code. While you could use a basic program like Notepad, a dedicated code editor offers features like syntax highlighting that make your code much easier to read. Python comes with a simple editor called IDLE, which is great for starting out. Many programmers use more advanced editors like VS Code, Sublime Text, or PyCharm.

Interpreter

noun

A program that directly executes instructions written in a programming language, without requiring them to be compiled into machine language first.

Your First Program

It's a tradition in programming to make your first program display the text "Hello, World!". Let's do that in Python.

First, open your text editor and create a new file. Save it as hello.py. The .py extension is important—it tells your computer that this is a Python file.

In that file, type the following single line of code:

# This line of code will print a message to the screen.
print("Hello, World!")

Now, save the file. To run it, you'll need to open a terminal or command prompt. Navigate to the directory where you saved hello.py and type the command:

python hello.py

When you press Enter, you should see Hello, World! printed in the terminal. You've just written and executed your first Python program.

Lesson image

How Python Runs Code

When you ran the python hello.py command, you were telling the Python interpreter to read and execute the code inside your file. The interpreter goes through your code line by line, from top to bottom. It reads print("Hello, World!"), understands that the print() function is a built-in command to display text, and then tells the operating system to show that text on the screen.

This line-by-line execution is what makes Python an interpreted language. It differs from compiled languages like C++, where the entire codebase is first translated into machine code by a compiler before it can be run.

That's the basic workflow: write code in a .py file, and use the interpreter to run it. With these fundamentals, you're ready to explore what makes Python so powerful.

Quiz Questions 1/5

What does it mean that Python is a "high-level" language?

Quiz Questions 2/5

You've saved your first Python program in a file named my_script.py. Which command do you use in the terminal to execute it?