No history yet

Introduction to Python

What Is Python?

Python is a programming language, a way to give instructions to a computer. Think of it less like complex engineering and more like learning a new spoken language. It's known for being readable and straightforward, with a syntax that’s clean and easy to grasp. This focus on simplicity was a core goal of its creator, Guido van Rossum, who released the first version in 1991.

Its power comes from its versatility. Programmers use Python for a huge range of tasks, from building websites and automating repetitive jobs to conducting complex data analysis and developing artificial intelligence. It's often called a "batteries-included" language because its standard library comes packed with tools for all sorts of common tasks.

Lesson image

You'll often hear Python described as a "high-level" and "interpreted" language. "High-level" means its syntax is closer to human language, which makes it easier to write and debug. An "interpreted" language is one where code is executed line by line by a program called an interpreter. This is great for beginners because you can run your code and see the results instantly, without a complicated compilation step.

Getting Set Up

To start coding, you need two things: Python itself and a place to write your code. The first part is the Python interpreter, the program that understands and runs your Python scripts. You can download the latest version for free from the official website, python.org. While many operating systems like macOS and Linux come with a version of Python pre-installed, it's always a good idea to install the most recent one.

Lesson image

Next, you need a code editor or an Integrated Development Environment (IDE). While you could write code in a simple text editor, an IDE provides helpful tools like syntax highlighting (coloring your code to make it more readable), autocompletion, and debugging aids. They make the process of writing and testing code much smoother.

Popular IDEs for Python include Visual Studio Code, PyCharm, and Thonny. For beginners, Thonny is a great choice because it comes with Python built-in and has a very simple interface.

Your First Script

Let's write a classic first program: one that simply prints "Hello, World!" to the screen. This is a simple tradition to confirm that your setup is working correctly.

Open your chosen editor or IDE and create a new file. Type the following line of code:

print("Hello, World!")

Here, print() is a built-in Python function that displays whatever you put inside the parentheses on the screen. The text inside the quotes is called a string.

Now, save the file. Python files should always end with the .py extension. A good name for this one would be hello.py.

To run your script, you can either use the "Run" button in your IDE or open your computer's terminal (or Command Prompt on Windows). In the terminal, navigate to the directory where you saved your file and type:

python hello.py

Press Enter. If everything is set up correctly, you should see Hello, World! printed in the terminal. You've just written and executed your first Python program.

Lesson image

This simple process of writing code in a file, saving it, and running it is the fundamental workflow for any Python developer.

Ready to check your understanding? Let's try a few questions.

Quiz Questions 1/5

What does it mean for Python to be a "high-level" language?

Quiz Questions 2/5

Which command would you typically use in a terminal to run a Python file named script.py?

With the basics covered, you're now ready to explore what makes Python such a powerful and popular language.