1
0

Python データ型編

Last updated at Posted at 2024-07-20

Python データ型編

Pythonで使用するデータ型について解説します。

目次

  1. 文字列(String)
  2. 整数(Integer)
  3. 浮動小数点数(Float)
  4. 論理値(Boolean)
  5. None型(NoneType)

1. 文字列(String)
文字列は、テキストデータを格納するためのデータ型です。シングルクォートかダブルクォートで囲んで表します。

String1.py
text = "Hello, World!"
print(text)  # Output: Hello, World!

文字列の操作例
文字列は、テキストデータを格納するためのデータ型です。シングルクォートかダブルクォートで囲んで表します。

String2.py
# 文字列の連結
greeting = "Hello"
name = "Alice"
message = greeting + ", " + name + "!"
print(message)  # Output: Hello, Alice!

# 文字列の部分抽出
substring = message[7:12]
print(substring)  # Output: Alice

2. 整数(Integer)
整数は、小数点を含まない数値です。

Integer.py
a = 10
b = -5
print(a + b)  # Output: 5

3. 浮動小数点数(Float)
浮動小数点数は、小数点を含む数値です。

Float.py
pi = 3.14
radius = 2.5
area = pi * (radius ** 2)
print(area)  # Output: 19.625

4. 論理値(Boolean)
論理値は、True または False の2値を持つデータ型です。

Boolean.py
is_sunny = True
is_raining = False
print(is_sunny and is_raining)  # Output: False

5. None型(NoneType)
論理値は、True または False の2値を持つデータ型です。

NoneType.py
value = None
print(value)  # Output: None

最後までお読みいただきありがとうございました。

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