No history yet

Introduction to Python

What is Python?

Python is a programming language, which is a way to give instructions to a computer. What makes Python special is how readable it is. Its syntax is clean and straightforward, almost like reading plain English. This makes it one of the best languages to learn first.

Simplicity is key. Python lets you write programs with fewer lines of code than most other languages.

It was created in the late 1980s by Guido van Rossum. Fun fact: he named it after the British comedy troupe Monty Python, not the snake. Since its creation, Python has been maintained and developed by a large community of volunteers.

What is Python Used For?

Python is incredibly versatile. You'll find it powering all sorts of applications, from small scripts that automate boring tasks to the complex systems behind major websites. It's a go-to language in many fields.

Lesson image

Here are a few popular uses:

  • Web Development: Frameworks like Django and Flask allow developers to build powerful web applications.
  • Data Science: Libraries like pandas and NumPy make Python a top choice for analyzing and visualizing data.
  • Machine Learning and AI: It's the dominant language for building artificial intelligence models, thanks to tools like TensorFlow and PyTorch.
  • Automation: Python is excellent for writing scripts that can handle repetitive tasks, like organizing files or sending emails.

Getting Python Running

To start writing Python, you need two things: the Python interpreter and a place to write your code. The interpreter is a program that reads your Python code and carries out its instructions.

Lesson image

You can download the official Python interpreter from the official website, python.org. The installation is straightforward for Windows, macOS, and Linux. If you're using Windows, make sure to check the box that says "Add Python to PATH" during installation. This allows you to run Python from your computer's command line.

Your Coding Environment

While you can write code in a simple text editor, most programmers use an Integrated Development Environment, or IDE. An IDE is a software application that combines a text editor with other helpful tools, like a debugger for finding errors and a shell for running code.

For beginners, we recommend the Thonny IDE. It's designed specifically for learning and teaching programming. It comes with Python built-in, so you don't need to install anything else.

Lesson image

Thonny's interface is simple and uncluttered. It shows you exactly what's happening with your variables as your program runs, which is a great way to understand how your code works step-by-step.

Basic Syntax and Structure

Python's structure is one of its most distinctive features. Unlike many languages that use curly braces {} to group code, Python uses indentation. This means the amount of whitespace at the beginning of a line is important. It forces you to write clean, organized code from the start.

Let's look at the classic first program, "Hello, World!" In Python, it's just one line.

print("Hello, World!")

Here, print() is a function that tells the computer to display text on the screen. The text you want to display goes inside the parentheses and is wrapped in quotes.

You also need to know about comments. A comment is a note in your code that the interpreter ignores. It's for you or other programmers to read. In Python, anything after a hash symbol # on the same line is a comment.

# This is a comment. The interpreter will ignore it.
print("This line will run.") # This is an inline comment.

Using comments is a good habit. They help explain what your code is doing, making it easier to understand later.

Quiz Questions 1/4

What is a key feature of Python's syntax that makes it distinct from many other programming languages?

Quiz Questions 2/4

Which of the following fields heavily relies on Python, using libraries like pandas and TensorFlow?