LoginSignup
0
1

More than 1 year has passed since last update.

Python データ型 (組み込み型)

Posted at

Pythonには様々なデータ型があります。
よく皆さんが使用するデータ型はint,float,str,list型でしょう。
これはどれもPythonに最初からある組み込み型です。
ここではPythonにある組み込み型を紹介します。

   型名              説明                        使用例                
str 文字列を表します。 a = "paison"
int 整数を表します。 b = -617
float 少数点のついた数(実数)を表します。 c = 3.14
complex 複素数という数の一種を表します。 d = 63 - 2.7j
bool 真、又は偽を表します。 e = True e = False
list リストを表します。 f = [5, True, 4.2, ["risuto", 4]]
print(f[3][0]) # ↳ risuto
tuple 組を表します。 g = (5, True, 4.2, ("たぷる", 8))
print(g[3][1]) # ↳ 8
dict 辞書を表します。 h = {3:6, "sakana":"魚", 3.14:"π"}
print(f["sakana"]) # ↳ 魚
type 変数のデータ型を表します。 i = {3:5,4:2}
print(type(i)) # ↳ <class 'dict'>
set 集合を表します。
listに似ていますが中にlistを挿入することはできません。
辞書に挿入したい場合は別の「frozenset」というデータ型を使います。
set([3,8,"raamen"]) # ↳ {8, 3, 'raamen'}
set([3,8,"raamen",[3,5.1]]) # ↳TypeError: unhashable type: 'list'

主な組み込み型を上に挙げました。
よく使うので覚えておくとよいでしょう。

0
1
5

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
0
1