1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pythonの " . " (ドット)って何

Last updated at Posted at 2025-03-18

pythonのピリオドって何(備忘録)

pythonの"."の役割を忘れてたのでまとめた

np.array

のように使われる"."(ドット)は
「オブジェクトの内部にアクセスするための記号」

1. インスタンスの属性やメソッドにアクセス

属性(データ)やメソッド(関数)に . を使うことでアクセスできる

class Person:
    def __init__(self, name, age):
        self.name = name  # インスタンスの属性
        self.age = age

    def greet(self):
        print(f"Hello, my name is {self.name} and I am {self.age} years old.")

# インスタンス(オブジェクト)の作成
person = Person("Alice", 25)

# 属性にアクセス
print(person.name)  # 出力: Alice
print(person.age)   # 出力: 25

# メソッドを呼び出す
person.greet()  # 出力: Hello, my name is Alice and I am 25 years old.
  • person.name → インスタンスpersonname属性を取得
  • person.greet() → インスタンスpersongreetメソッドを呼び出し

2. モジュールやパッケージの関数・クラス・変数にアクセス

Numpyのdot関数の場合

import numpy as np

# 2つのベクトルの内積を計算
vector1 = np.array([1, 2, 3])
vector2 = np.array([4, 5, 6])

result = np.dot(vector1, vector2)  # NumPyのdot関数を使う
print(result)  # 出力: 32
  • np.dot()numpyモジュールのdot関数を呼び出す
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?