LoginSignup
1
0

More than 3 years have passed since last update.

Python超初心者の超初心者のためのPython #型(type)と型(type)の確かめ方

Last updated at Posted at 2020-06-08

環境
windows7 (Mac Book Pro 16inch欲しい)
Visual Studio Code
chrome

この記事はプログラミング初心者かつPython初心者に向けて記述します。

1.Pythonの型(type)の種類と型(type)の確かめ方

integer

1
123
-1234

等の数(整数)。プラスもマイナスも含みます。

style.py
print(type(1))
#<class 'int'>「整数だよー」と言っている。

print(type(123))
#<class 'int'>これも「整数だよー」

print(type(-1234))
#<class 'int'>マイナスでも「整数だよー」

string

こんにちは
Hello Python
I'll be back
Comment allez-vous?
コロナはもうたくさんだ

等の文字(文字列)です。

type.py
print(type("こんにちは"))
#<class 'str'>stringの頭文字3つを取って'str'。つまり文字(文字列)です。

print(type("Hello Python"))
#<class 'str'>これも「文字列ですよー」と言っている。

print(type("Comment allez-vous?"))
#<class 'str'>フランス語でも「文字列ですよー」

print(type("コロナはもうたくさんだ"))
#<class 'str'>ウィルスも「文字列ですよー」

floating point numbers

1.0
-3.14

等の小数点(浮動小数点数*1)
*1浮動小数点数ってなにそれ?はこちらに詳しく記載されています。

type.py
print(type(1.0))
#<class 'float'>floating pointの頭文字5つを取って'float'。つまり小数点(浮動小数点数)です。

print(type(-3.14))
#<class 'float'>マイナスでも「小数点(浮動小数点数)だよー」

complex numbers

3j
3.21j

虚数。なんのこっちゃ!
ググってみたらこちらがわかりにくいけどわかりやすく書かれています。

type.py
print(type(3j))
# <class 'complex'>「きょっ、虚数です!」

print(type(3.21j))
# <class 'complex'>「八丈島のキョ・・・ではなくて虚数です。」

boolean

True(Tは大文字)
Fals(Fは大文字)
幸いなことにbooleanはこの2種類しかないです。「わたくしbooleanと書いてブーリアンと発します」

type.py
print(type(True))
# <class 'bool'>「ブーリアンです」

print(type(False))
# <class 'bool'>「高木ブーリアンです」

***
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0