Introduction & Setup

Section Overview

This section will help you get started with Python. You’ll learn what Python is, why it’s useful, how to set it up on your computer, and how to write and run your first Python program. We’ll keep things simple and focus on getting you writing code as quickly as possible.

Lesson 1: What is Python?

Python is a general-purpose programming language that emphasizes simplicity and readability. It’s used in a wide range of industries—from web development and automation to data science and artificial intelligence. Python’s gentle learning curve makes it an ideal first language.

Examples of where Python is used:

  • Web development (e.g., Instagram, YouTube)
  • Automation and scripting
  • Data analysis and visualization
  • Game development and AI

If you're new to programming, Python is a great place to begin.


Lesson 2: Setting Up Python

Before we write any code, you’ll need two things:

  1. The Python interpreter
  2. A code editor (a tool where you'll write your code)

Step 1: Install Python

  • Visit python.org/downloads
  • Download the version for your operating system
  • During installation, make sure to check the box that says "Add Python to PATH"
  • Complete the installation and verify by opening your terminal or command prompt and running:
python --version

Step 2: Choose an Editor

Either will work, but Thonny is a good choice if this is your first time programming.


Lesson 3: Writing Your First Python Program

Let’s write a basic Python script. Open your editor and type:

print("Hello, world!")

Save the file as hello.py, then run it. You should see:

Hello, world!

This is your first Python program. It prints a message to the screen using the print() function.


Lesson 4: Getting Input from the User

Programs become more interesting when they interact with users. Here’s how to ask a question:

name = input("What is your name? ")
print("Nice to meet you, " + name + ".")

This program:

  • Uses input() to collect the user's name
  • Stores it in a variable called name
  • Prints a greeting that includes their name

Try modifying it to ask for their age, or favorite color.


Quiz: Check Your Understanding

1. What is the purpose of the print() function in Python?
a) It stores data
b) It performs calculations
c) It displays information to the user
→ Answer: c)

2. What does the following code do?

name = input("Enter your name: ")

a) Defines a function
b) Gets input from the user and stores it in a variable
c) Creates a loop
→ Answer: b)

3. True or False: You must always store input in a variable.
→ Answer: False — you can use input without storing it, but storing it makes it useful.

4. What symbol is used for a string in Python?
→ Answer: Quotation marks (" or ')


Practice Exercise: Personalized Welcome Message

Create a simple Python program that asks the user for their name and age, and then prints a welcome message.

Example Output:

Welcome to Python!
What is your name? Sam
How old are you? 30
Hello Sam, you are 30 years old.

Starter Code:

print("Welcome to Python!")

name = input("What is your name? ")
age = input("How old are you? ")

print("Hello " + name + ", you are " + age + " years old.")

Challenge: Ask one more question (like favorite color or city) and include it in the final message.