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.

Learn about molds

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

Learn about variables

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.

This is the end of this exercise. Please look forward to next time. Go to Table of Contents

Recommended Posts

Getting Started with python3 # 2 Learn about types and variables
Getting Started with python3 # 1 Learn Basic Knowledge
1.1 Getting Started with Python
Getting Started with Python
Getting Started with Python
Getting Started with Python Functions
About Python variables and objects
Getting Started with Python Django (1)
Getting Started with Python Django (4)
Getting Started with Python Django (3)
Getting Started with Python Django (6)
Python3 | Getting Started with numpy
Getting Started with Python Django (5)
Getting Started with Python responder v2
Getting Started with Python Web Applications
Getting Started with Python for PHPer-Classes
Getting Started with Python Basics of Python
Getting Started with Python Genetic Algorithms
Getting started with Python 3.8 on Windows
Getting Started with Python for PHPer-Functions
Getting Started with Python Web Scraping Practice
Getting Started with Python for PHPer-Super Basics
Getting Started with Python Web Scraping Practice
Getting started with Dynamo from Python boto
Getting started with Python with 100 knocks on language processing
Python variables and data types learned in chemoinformatics
[Translation] Getting Started with Rust for Python Programmers
Trouble with Python pseudo-private variables and class inheritance
Getting started with AWS IoT easily in Python
[Python] Learn about asynchronous programming and event loops
Django Getting Started Part 3 about Python3 & MySQL Connector
Materials to read when getting started with Python
Settings for getting started with MongoDB in python
Django 1.11 started with Python3.6
Getting started with Android!
Learn Python with ChemTHEATER
Getting Started with Golang 2
Getting started with apache2
Getting Started with Golang 1
Getting Started with Django 1
Getting Started with Optimization
Getting Started with Golang 3
Getting Started with Numpy
Getting started with Spark
Getting Started with Pydantic
Getting Started with Golang 4
Getting Started with Jython
Getting Started with Django 2
For those who want to learn Excel VBA and get started with Python
Getting Started with Google App Engine for Python & PHP
Getting Started with Tensorflow-About Linear Regression Hypothesis and Cost
Getting Started with Yocto Project with Raspberry Pi 4 and WSL2
Translate Getting Started With TensorFlow
Programming with Python and Tkinter
Encryption and decryption with Python
Python: Class and instance variables
Getting Started with Tkinter 2: Buttons
Python and hardware-Using RS232C with Python-
Getting Started with Go Assembly
Getting Started with PKI with Golang ―― 4
About python objects and classes