Python Programming Fundamentals
Python Basics
Getting Python Ready
Python is a popular programming language known for its clear and readable syntax. It's a great choice for beginners because it lets you write powerful programs with very little code.
Before you can start writing, you need to make sure Python is installed on your computer. Many operating systems, like macOS and Linux, come with an older version of Python already installed. However, it's always best to use the latest official version. You can download it directly from the official Python website, python.org.
Once Python is installed, you need a place to write your code. You can use any plain text editor, but most programmers use a special tool called an Integrated Development Environment (IDE) or a code editor. These tools offer helpful features like syntax highlighting, which colors your code to make it easier to read, and debugging tools to help you find errors.
Python comes with its own simple IDE called IDLE, which is perfect for starting out. Other popular free options include Visual Studio Code, PyCharm Community Edition, and Atom. Don't worry too much about which one to pick; they all get the job done.
Your First Program
Let's write your first program. It's a tradition for new programmers to start by making the computer say "Hello, World!". This simple task confirms that your setup is working correctly and introduces you to a fundamental concept: displaying output.
To do this in Python, we use the print() function. A function is a reusable block of code that performs a specific action. The print() function's job is to display whatever you put inside its parentheses on the screen.
# The print() function displays text to the screen.
# The text inside the quotation marks is called a string.
print("Hello, World!")
Type that code into your editor, save the file with a .py extension (like hello.py), and then run it. You can usually run the file from a menu option in your IDE or by typing python hello.py in your computer's terminal. If everything is set up correctly, you'll see Hello, World! printed out.
Talking to Your Program
Displaying static text is useful, but programs become much more interesting when they can interact with a user. Python makes it easy to get input from the user with the input() function.
When your program calls input(), it pauses and waits for the user to type something and press Enter. Whatever the user types is then returned by the function as a string of text, which you can store in a variable to use later.
variable
noun
A named storage location in a computer's memory that holds a value. You can change the value of a variable.
Let's combine input() and print() to create a program that asks for a user's name and then greets them.
# 1. Ask the user for their name and store it in a variable called 'name'.
# The text inside input() is the prompt shown to the user.
name = input("What is your name? ")
# 2. Print a greeting that includes the user's name.
# We can combine strings using the + operator.
print("Hello, " + name + "!")
When you run this code, it will first display "What is your name? ". After you type your name and press Enter, it will print a personalized greeting.
Notice the syntax. The equal sign = is the assignment operator. It takes the value on the right (the result of the input() function) and stores it in the variable on the left (name). Python's syntax is designed to be clean and readable, often resembling plain English.
What is the primary function used in Python to display text on the screen?
Which line of code correctly asks the user for their name and stores it in a variable called username?
You've successfully set up your environment, written a program, displayed output, and received input from a user. These are the fundamental building blocks of any Python application.

