# Getting Started with python3 # 2 Learn about types and variables

Hi, my name is beatbox4108. This time, I was planning to learn about advanced math ... but I would like to learn about python's type and variable, which need explanation. __Note: From this time on, the number of times the interactive shell is used will increase exponentially. Please check how to use it. __

# Target person

Beginners in programming and trying to learn python Teachers who want to use python in the field of education but do not know how to explain

# Premise

python3 is installed on your pc. Understand how to use the development environment. I understand the exercises up to the last time.

## First of all

The type in python represents the type of data. The basics are:

Type name Type of type Type usage example
int Handles integer values. `4108`
float Handles decimal numbers. `41.08`
str Handles strings. `"beatbox4108"`
bool Handles Booleans. `True`

There is a strange type called bool, but I will explain it in detail later.

## What are int type and float type!

We handle numbers as we saw in the table above. To force an int type to a float type, use the ``float ()`` function. To force a float type to an int type, use the ```int () `` `function.

Example:

``````>>> int(41.08)
41
>>> float(4108)
4108.0
``````

## What is the str type!

As we saw in the table above, we are dealing with strings (strings of characters). Many types, such as int types, can be converted to str types using the ``str ()`` functions.

The str type has many methods.

### Wait a minute, what is a method!

A method is a function __like __ that summarizes operations related to types. (I'm sorry if it's different.) The method calls the data like a function, with a `` `.``` (period) after the data. Like this:

``````>>> "beatbox4108".replace("4108","8192")
"beatbox8192"
``````

The frequently used methods of str type are summarized in the table. Please check for details.

Method name Description how to use Return value
replace Replace character `.replace(String before replacement,Character string after replacement)` Character string after replacement(str type)
split Split a string by specific characters `.split(Delimiter)` List after split(list type)
upper Uppercase the alphabet `.upper()` The changed character string(str type)
lower Make all letters lowercase `.lower()` The changed character string(str type)

The return value is the data that is returned when you use the function. The return value of the `split` method is a list type, you may not know, but I will explain it from the next time.

## I don't understand bool type at all!

As you can see in the table above, bool type cannot be explained !! Take a second look, the bool type is a special type, represented by __`` `True``` and` `False```. True and False have the following meanings:

True False
Positive false

You may hear a voice saying "I don't understand at all" __, but I will explain it when studying conditional expressions. By the way, True and False can be inverted with not.

``````>>> not True
False
``````

## First of all

In python, variable is like giving a name (name tag) to a value. Variables can be created and modified in the format `variable name = value`. When reading a variable, you can read it by entering the variable name instead of the value.

You love math:

Why did I write `x = 1`? If you enter `x = 2`,` x` will be 2!

Example:

``````>>>hello="Hello"
>>>print(hello)
Hello
``````

## Techniques when using variables

You can omit the four arithmetic operations by writing as follows. Before omission:

``````x=10
x=x+3
x=x-3
x=x*3
x=x/3
print(x)
``````

After omission:

``````x=10
x+=3
x-=3
x*=3
x/=3
print(x)
``````

# This summary

Type in python represents the type of data. In python, variable is like a box to put data in. Variables can be created / modified in the format `variable name = value`. When reading a variable, you can read it by entering the variable name instead of the value.