#6 Python Playground: Variables & Data Types | Computer Programming & Coding for Kids & Beginners

preview_player
Показать описание
Lesson6 Variables and Data Types

6-1

Liam
Variables and Data Types

How does Emma eat sweets?
You must put "juice" in a "cup" and "pancake" on a "plate" to eat.

Emma
That's right.
I love sweets.

Liam
Actually, even in a program, the vessel is important.
We handle "data" in a "container" too.
This "data container" is called a "variable".

Emma
We will put our data in a "variable" like sweets, too.

Liam
There are so many different types of sweets to put on your plate.
There are many different types of data that you can put into a variable like this.
This is called a "data type”.

Emma
Now that I've heard about the sweets, I'm getting hungry.

6-2

Liam
How to Use Variables

When writing code, data can be used by putting it in a "container" called "variable".
Variables that contain data can be used instead of that data.

Now, let's put the value in the variable and display it.
Create, save and run the following program.

a = 10 ・ ・・・・・・・・変数に値を代入
print(a) ・・・・・・・変数の中身を表示

出力結果10

Emma
The content of the variable is displayed.
What does a variable mean?

Liam
Variables are ambiguous, "the number that can be changed".

Emma
What's the advantage of being able to change the contents of a variable?

Liam
The same program can change the results by simply changing the contents of the variables.
In other words, you can just change the content of the variables and get results accordingly.

Emma
That's convenient.
We can reuse the same program just by changing the contents of the variable.

Liam
That’s right.
Now let's calculate using variables.
Create, save and run this program.

a=2
b=3
c=a+b
print(c)

出力結果
5

Emma
The calculation result is displayed.

Liam
Next let’s change the value in variables using same program.
Create, save and run this program.

a=15
b=26
c=a+b
print(c)

出力結果
41

Emma
The calculation result is displayed according to the value contained in the variable.

6-3

Liam
Data Type

There are so many different types of sweets to put on your plate.
There are many different types of data that you can put into a variable like this.
This is called a "data type".
There are several types, such as "integer" for integers, "floating point" for decimals, "string" for characters, and "boolean" for true or false.

Many programming languages require you to pay attention to these data types in your programs, but Python allows you to work with them without paying attention to them.
Any data type can be put into a variable in the same way.
Let's create variables with various data types.
Create, save and run this program.

x=100
y=3.5
z=“Hello”
abc=True
print(x,y,z,abc)

出力結果
100 3.5 Hello True

Emma
The various data types are displayed.
We were able to put various kinds of data into variables.

6-4

But if python doesn't need us to pay attention to data types, don't we need to know about them?

Liam
Let's keep in mind that there are many different types of data.
That's because different kinds of data can't be processed in the same way.

Emma
It's a pain to learn about so many data types.

Liam
So can you add cold juice to the hot cup of coffee?
Wouldn't it be better to have the same kind of drink in a cup?

Emma
As Liam says, it's better to handle the same types at the same time.
In this lesson, we learned about variables and data types.

Liam
Well done.
Рекомендации по теме
Комментарии
Автор

This is for school.. oh no nu-uh I ain’t doin this is way too creepy 😭

i.eat_kids
Автор

bruh this for school...oh nu-uh I ain't letting my children do this in school hell nah

korkormensah