Your First Steps in Python: A Beginner to Intermediate Guide

Assigning Values to Variables: Giving Data a Home

Section 3

Variables and Operators: Storing and Manipulating Data

Your First Steps in Python: A Beginner to Intermediate GuideVariables and Operators: Storing and Manipulating Data

Welcome to the exciting world of programming! In Python, we need a way to store information so we can use it later. This is where variables come in. Think of a variable as a labeled box where you can put a piece of data. You give the box a name (the variable name) and then you can put something inside it (the value).

To put a value into a variable, we use the assignment operator, which is the equals sign (=). It's super straightforward: you write the variable name, then an equals sign, and then the value you want to store. This operation is called 'assignment'.

my_variable = 10

In the code above, my_variable is the name of our variable, and 10 is the value we are assigning to it. Python will create a box named my_variable and place the number 10 inside.

Variables can hold different types of data. Let's see some examples:

name = "Alice"
 age = 25
 height = 5.9
 is_student = True

Here, name holds a string of text, age holds an integer (a whole number), height holds a floating-point number (a number with a decimal), and is_student holds a boolean value (either True or False). Python is smart enough to figure out the type of data you're storing.

graph TD;
    VariableBox["my_variable"]
    Value[10]
    VariableBox --> Value;
チャプターへ戻る