Introduction to Python Programming
Python Basics
Getting Started with Python
Python is a popular programming language known for its clear, readable syntax. It’s a great choice for beginners because it lets you write powerful programs with very few lines of code. Before you can start writing, you'll need to install it on your computer.
Head to the official Python website, python.org, and download the latest version for your operating system. The installer will guide you through the setup. During installation, make sure to check the box that says "Add Python to PATH." This small step makes it much easier to run your programs from the command line later on.
Along with the language itself, you'll get a simple program called IDLE (Integrated Development and Learning Environment). An IDE is a tool that combines a text editor with other helpful features for programmers. IDLE is a great place to start writing your first lines of Python.
Your First Python Script
In programming, it's a tradition to make your first program display the text "Hello, World!". This is a simple way to confirm that your setup is working correctly. In Python, you can do this with a single line of code using the print() function.
The
print()function is a built-in command that tells the computer to display whatever you put inside the parentheses on the screen.
Open IDLE or any text editor and type the following:
# This line of code will print a message to the screen.
print("Hello, World!")
Save the file with a .py extension, for example, hello.py. The .py ending tells the computer that this is a Python script. To run it, you can usually press a "Run" button in your IDE or open a terminal, navigate to the folder where you saved your file, and type python hello.py.
Syntax and Indentation
Python's syntax refers to the set of rules that define how a program is written. One of the most important and unique rules in Python is its use of indentation.
Unlike many other languages that use brackets or keywords to group code, Python uses whitespace. The amount of space at the beginning of a line is meaningful. While this might seem strange at first, it forces programmers to write clean, organized code. For now, just remember that you shouldn't indent lines of code unless there's a specific reason to do so, which we'll cover later.
Incorrect indentation is one of the most common errors for beginners. Always be mindful of your spaces!
Basic Input and Output
You've already seen how to produce output with the print() function. But what if you want your program to get information from the user? For that, you can use the input() function.
The input() function pauses your program and waits for the user to type something and press Enter. It's common to provide a prompt to let the user know what you're asking for. Here’s an example:
# Ask the user for their name and store it in a variable.
name = input("What is your name? ")
# Greet the user by name.
print("Hello, " + name)
In this script, name = input(...) asks the user for their name and saves their response in a variable called name. A variable is simply a container for storing data. The next line then uses print() to combine the string "Hello, " with the user's input to create a personalized greeting.
When installing Python from the official website, which option is important to check to make running programs from the command line easier?
Which line of Python code correctly displays the text 'Hello, World!' on the screen?
That's it for the very basics. You've set up your environment, written and run a script, and learned how to communicate with the user. You're now ready to build on these fundamentals.

