No history yet

Introduction to Python

What is Python?

Python is a programming language known for its readability. Its design philosophy emphasizes code that's easy to write and understand, which makes it a great choice for beginners.

It was created in the late 1980s by Guido van Rossum. He wanted to make a language that was both powerful and simple. The name doesn't come from the snake, but from the British comedy group Monty Python. This playful spirit is a small part of Python's culture.

One of Python's core principles is that "Readability counts." Code is often read more than it's written, so making it clean and clear is a top priority.

Python is incredibly versatile. You can find it powering web applications, analyzing data, automating tasks, and driving scientific research. A huge and active community supports the language, creating a vast ecosystem of libraries and tools that extend its capabilities.

Getting Your Environment Ready

To start writing Python, you need a Python interpreter. This is a program that reads and executes your Python code. You can download it for free from the official Python website, python.org.

When you install Python, it often comes with a simple Integrated Development and Learning Environment (IDLE). This is a basic tool that includes a text editor for writing your code and a shell for running it. It’s a great place to start.

Lesson image

Once you have Python installed, you can test it with a classic first program.

print("Hello, World!")

This line of code uses the print() function to display the text "Hello, World!" on the screen. We'll look more at input and output later. For now, running this simple command confirms your setup is working.

Syntax and Spacing

Every language has rules of grammar, and programming languages have syntax. One of Python's most distinct syntax rules is its use of indentation.

In many other languages, programmers use curly braces {} to group lines of code into blocks. Python doesn't. Instead, it uses whitespace—specifically, indentation. A new line indented with four spaces signals that it's part of a block of code. While we won't be writing complex blocks yet, it's a fundamental rule to know from the start.

Consistent indentation is not just for style in Python; it's a requirement. This makes all Python code look clean and structured in a similar way.

Storing Information

In programming, we need places to store information. We use variables for this. A variable is like a labeled box where you can put a piece of data. You give the box a name, and you can change what's inside it later.

Creating a variable is simple. You just choose a name, use the equals sign (=), and provide the value you want to store.

# Assigning the number 42 to the variable 'answer'
answer = 42

# Assigning the text 'Arthur Dent' to the variable 'name'
name = "Arthur Dent"

The data we store comes in different forms, or data types. Python is smart and usually figures out the type on its own. Let's look at a few basic types.

Data TypeDescriptionExample
intInteger, a whole number.42
floatFloating-point number, a number with a decimal.3.14
strString, a sequence of characters, like text."Hello"
boolBoolean, a value that is either True or False.True

These fundamental types are the building blocks for handling all kinds of information in your programs.

Talking to the User

Programs are more interesting when they can interact with a user. We've already seen how to display information using the print() function. This is a form of output.

To get information from a user, we use the input() function. This function displays a message to the user, waits for them to type something, and then returns whatever they typed as a string.

# The text inside input() is the prompt shown to the user
user_name = input("What is your name? ")

# Now we can use the variable to print a personalized greeting
print("Hello, " + user_name + "!")

When you run this code, it will first ask "What is your name? ". After you type your name and press Enter, it will greet you. Notice how we can combine, or concatenate, strings using the + operator.

This simple back-and-forth is the basis for all user interaction in programming.

Ready to check your understanding?

Quiz Questions 1/5

What does Python use to group blocks of code, unlike many other languages that use curly braces {}?

Quiz Questions 2/5

Who is the creator of the Python programming language?

You've just taken your first steps with Python. You've seen where it comes from, how to get it running, and how to handle basic data and user interaction. These are the core skills you'll build on as you learn more.