クラス

ソースコード
    #coding:utf-8
    #class 2025/2/12

    #classの定義:classはあるオブジェクトのテンプレート
    #クラスの名前は第一文字は大文字で、残りは小文字とする

    class Car:       #関数のパラメータ、引数(数学における関数やコンピュータプログラムにおける手続きにおいて、その外部と値をやりとりするための特別な変数、あるいはその変数の値のこと)
        def __init__(self,brand,color,type,price,picture):#initialize 初期化
    
            self.brand = brand
            self.coler = color
            self.type = type
            self.price = price
            self.picture = picture

        #methods 方法の定義
        def info(self):
            print(f'The car of {self.brand} is {self.coler}, type is {self.type}.')
            print(f'{self.picture} 価格={self.price}')

    Nissan = Car("Nissan","Black","nismo","9000000","./images/Z.jpg")
    Nissan.info()

    class Person:
        def __init__(self,f_name,l_name):

            self.firstname = f_name
            self.lastname = l_name

        def print_name_eng(self):
            print(self.firstname,self.lastname)

        def print_name_jp(self):
            print(self.firstname,self.lastname)

    x=Person("山口","璃恩")
    x.print_name_jp()

    y=Person("Jason","Statham")
    y.print_name_eng()

    class Rectangle:
        def __init__(self,length,width):
            self.rect_length=length
            self.rect_width=width

        def print_area(self):
            print(f"面積 = {self.rect_length * self.rect_width}")

    for i in range(3):
        x=int(input("長方形の縦幅: "))
        y=int(input("長方形の横幅: "))
        shape = Rectangle(x,y)
        shape.print_area()
実行結果