Lesson 2: Variables and Data Types

Lesson 2: Variables and Data Types

In this lesson, we’ll learn how to store information in variables and explore different data types. Think of variables like labelled boxes where you can keep important bits of information—your name, age, or even whether you like pizza!

Lesson 1: Introduction to Python and Setup

Introduction

Welcome back to your Python adventure! In this lesson, we’ll learn how to store information in variables and explore different data types. Think of variables like labelled boxes where you can keep important bits of information—your name, age, or even whether you like pizza!

By the end of this lesson, you’ll:

  • Understand what variables are.

  • Learn about different data types (numbers, words, and more!).

  • Create a fun program that introduces YOU!

[cl_logged_in]

What is a Variable?

Imagine you have a magical notebook where you can write down and update information. In Python, a variable is like a name tag that holds a piece of information.

Here’s an example:

In this example:

  • name is a variable that stores the word "Alex".
  • age is a variable that stores the number "12".

You can think of it like this:

  • name → 📦 "Alex"
  • age → 📦 12

Python remembers these values for you!

[/cl_logged_in]

[cl_logged_in]

Data Types: Different Kinds of Information

Python has different types of data. Let’s look at the four main ones:

 

1. Strings – Words and Sentences

A string is a piece of text (letters, words, or sentences). Strings are always written inside quotation marks.

 

2. Integers – Whole Numbers

An integer is a whole number (no decimal point!).

 

3. Floats – Decimal Numbers

A float is a number that has a decimal point.

 

4. Booleans – True or False

A boolean is like a yes/no switch. It can only be True or False.

 

[/cl_logged_in]

[cl_logged_in]

Let’s Practice: Your “About Me” Program

Now, let’s put everything together and create a fun program that introduces YOU! 🎉

 

Step 1: Create Variables

Fill in your own details:

 

Step 2: Print Your Info

Now, let’s print out a little introduction!

 

Step 3: Run Your Program!

Press Run, and see your Python program introduce you! 🚀

 


Challenge: Add More!

Try adding more details about yourself. Here are some ideas:

  • Your favourite animal 🐶
  • Your dream holiday destination ✈️
  • Your favourite hobby 🎨

Example:

Here is some example code for you to try, feel free to add to it.

# About Me Program

# Step 1: Create Variables
name = “Your Name” # Replace with your name
age = 12 # Replace with your age
favourite_colour = “Blue” # Replace with your favourite colour
likes_pizza = True # Change to False if you don’t like pizza

# Step 2: Print Your Information
print(“Hello! My name is ” + name + “!”)
print(“I am ” + str(age) + ” years old.”)
print(“My favourite colour is ” + favourite_colour + “.”)
print(“Do I like pizza? ” + str(likes_pizza))

# Step 3: Add More Fun Facts
favourite_animal = “Penguin” # Replace with your favourite animal
dream_holiday = “Japan” # Replace with your dream travel destination

print(“I love ” + favourite_animal + “s and I want to visit ” + dream_holiday + ” one day!”)

 

Remember: Lines that start with a # are comments only and will not be processed as code.

[/cl_logged_in]

[cl_logged_out]

Members Only

You need to be registered and logged in to access this full python lesson and all other learning resources, games and quizzes.

[/cl_logged_out]

Summary of This Lesson

✅ What variables are
✅ Different types of data (strings, integers, floats, booleans)
✅ How to use print() to display your information
✅ How to create a fun “About Me” program! 

Next time, we’ll learn how to get user input so your program can ask questions. Stay curious and keep coding! 🚀

Next Lesson: User Input and Basic String Manipulation

In the next lesson, we will learn how to accept user input and manipulate strings.

Leave a comment