Introduction to Python Programming
Introduction to Python
What is Python?
Python is a programming language known for its clear, readable syntax. Think of it less like a dense legal document and more like a well-written set of instructions. It was created in the late 1980s by Guido van Rossum, who wanted to make a language that was both powerful and easy to understand.
Its simplicity doesn't limit its power. Python is used everywhere, from building websites and apps (like Instagram and Spotify) to processing huge amounts of data in science and finance. Its versatility comes from a massive collection of pre-written code, called libraries, that you can use to perform complex tasks without starting from scratch.
Getting Started
To start writing Python, you need two things: the Python interpreter and a place to write your code. The interpreter is what reads your Python code and translates it into instructions the computer can execute. You can download it for free from the official Python website, python.org.
While you could write code in a simple text editor, most developers use an Integrated Development Environment, or IDE. An IDE is a software application that combines a text editor with other helpful tools, like code completion and a debugger, to make programming easier. Popular choices for Python include Visual Studio Code (VS Code) and PyCharm.
Your First Program
A long-standing tradition in programming is to make your first program display the text "Hello, World!". In Python, this is incredibly simple. It takes just one line of code using the print() function.
print("Hello, World!")
The print() function takes whatever is inside the parentheses and displays it on the screen. Here, we gave it a string of text, which must be enclosed in quotes.
Now let's try getting information from the user. For that, we use the input() function. It pauses the program, waits for the user to type something and press Enter, and then returns what they typed.
# Ask the user for their name
name = input("What is your name? ")
# Greet the user
print("Hello, " + name + "!")
In this example, we first display the question "What is your name? " to the user. Their answer is then stored in a variable called name. Finally, we use print() again to display a personalized greeting.
Python's Rules
Every language has rules, and Python is no different. Its syntax is designed to be clean and uncluttered. One of the most important and unique rules in Python is its use of indentation.
Instead of using curly braces
{}or keywords to group lines of code into blocks, Python uses whitespace. Lines of code that are part of the same block must be indented by the same amount.
This might seem strange at first, but it forces everyone to write code that is formatted consistently and is easy to read. You typically use four spaces for each level of indentation. Don't worry about the if statement for now; just notice the indentation.
temperature = 75
if temperature > 70:
print("It's a warm day.")
print("Wear something light.")
Another key part of writing good code is documentation. You can leave notes for yourself or other programmers right inside your code using comments. The Python interpreter ignores comments, so they don't affect how the program runs.
To write a comment, just start the line with a hash symbol (#).
# This is a comment. It won't be executed.
# Use comments to explain what your code does.
# Calculate the area of a rectangle
length = 10 # Length of the rectangle
width = 5 # Width of the rectangle
area = length * width
print(area) # This will print the result
Now that you have a handle on the basics, let's review what we've learned.
Time to check your understanding.
Who is the creator of the Python programming language?
What is the primary purpose of the Python interpreter?
You've taken your first steps into Python. You've set up your environment, written a program that interacts with a user, and learned the fundamental rules of Python syntax. You're ready to build on this foundation.

