クラスについて

https://www.dropbox.com/sh/8l44b8x4of0zz7j/AACTB566DESGBhJWwh4Li3KYa?dl=0

クラスというのは

簡単にいうと

関数と変数をまとめたものになります

まずは、基本的な作り方と使い方です

1.py

FirstClassというクラスを作り

「hello1」「hello2」「hello3」

という関数を作っています

#coding:utf-8

'''

クラスについて説明します

'''

#classの基本構文

class FirstClass:

def hello1(self):

print('hello')


def hello2(self):

pass #何もおこらない


def hello3(self,name):

print ('hello' + name)


#実行方法

c=FirstClass()

c.hello1()

c.hello3('mitani')

------------------------------

2.py

変数の使い方です

#coding:utf-8

'''

クラスについて

続き

'''

#classの基本構文

class FirstClass:

#初期値をここに作ってもいい

msg_syoki='さようなら'

def __init__(self):

#最初に実行される

#初期値などを作る

self.msg='おげんきですか'


def hello(self):

msg='こんにちは'

print(msg)

print(self.msg)

print(self.msg_syoki)


#実行

c=FirstClass()

c.hello()