No history yet

Introduction to Python

Meet Python

Python is a popular programming language known for being powerful yet easy to read. Its syntax is clean and straightforward, which often makes people feel like they're writing in a version of English. This simplicity is a big reason why it's a favorite for beginners and experts alike.

Created in the late 1980s by Guido van Rossum, Python was designed with a core philosophy: code should be easy to read and write. This idea is captured in a set of principles called "The Zen of Python." One of its guiding rules is that there should be one, and preferably only one, obvious way to do something. This keeps code consistent and simple.

A key principle in Python is that readability counts. Clear code is better than clever code.

One of the most distinct features of Python is its use of indentation. Instead of using brackets or keywords to group code, Python uses whitespace. This forces programmers to write visually clean and organized code. For example, any code that's part of a loop is simply indented underneath the loop's first line. You get used to it quickly, and it makes reading code much easier.

Python is also versatile. It supports several different ways of writing programs, known as programming paradigms. You can write in a procedural style, like a simple recipe with step-by-step instructions. You can use an object-oriented approach, which involves creating reusable blueprints (called classes) for objects, much like building with LEGO bricks. It also supports functional programming, which treats computation like mathematical functions, avoiding changing state and mutable data.

Setting Up Your Workspace

Before you can start coding, you need to install Python on your computer. You can download the latest version from the official website, python.org. The installation process is straightforward for Windows, macOS, and Linux.

Once Python is installed, you'll need a place to write your code. While you can use a simple text editor, most developers use an Integrated Development Environment (IDE). An IDE is a software application that provides comprehensive facilities to programmers for software development. Think of it as a supercharged text editor that understands your code, points out errors, and helps you run and debug your programs.

Lesson image

For beginners, some great choices are VS Code (Visual Studio Code) and PyCharm. Both have free versions and are widely used in the industry. They offer features like syntax highlighting, which colors your code to make it more readable, and code completion, which suggests code as you type.

Your First Program

Let's write your first Python program. It's a tradition in programming to start with a program that simply displays "Hello, World!" on the screen. It's a small victory that proves your setup is working correctly.

Open your IDE or text editor, create a new file, and save it as hello.py. The .py extension is important because it tells the computer that this is a Python file. Now, type the following line of code into the file:

# This is a comment. Python ignores anything after a #
# The print() function displays text on the screen.
print("Hello, World!")

That's it! The print() function is a built-in Python command that outputs whatever you put inside the parentheses. To run your program, open your computer's terminal or command prompt, navigate to the directory where you saved hello.py, and type python hello.py or python3 hello.py, then press Enter. You should see Hello, World! printed in the terminal.

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

Time to check what you've learned.

Quiz Questions 1/6

Who is the creator of the Python programming language?

Quiz Questions 2/6

What is the primary purpose of using indentation in Python?

Now that you have your environment set up and have run your first program, you're ready to dive deeper into the fundamentals of the language.