「Python入門」コンストラクタを使うサンプル

2020年11月6日

構文
def __init__(self):
self.data = []
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
class User:
def __init__(self, name):
self.userName = name
cft = User("TestUser")
print(cft.userName)
# coding: utf-8 class User: def __init__(self, name): self.userName = name cft = User("TestUser") print(cft.userName)
# coding: utf-8

class User:
    def __init__(self, name):
        self.userName = name

cft = User("TestUser")
print(cft.userName)

結果
TestUser

Python

Posted by arkgame