From d44a6725b86dbf26ff2f1b626fb16475d57e9086 Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Mon, 6 May 2024 08:02:31 +0200 Subject: [PATCH] Add examples for defining a class Signed-off-by: Christopher Arndt --- beispiele/personclass1.py | 27 +++++++++++++++++++++++++++ beispiele/personclass2.py | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 beispiele/personclass1.py create mode 100644 beispiele/personclass2.py diff --git a/beispiele/personclass1.py b/beispiele/personclass1.py new file mode 100644 index 0000000..a55fcd1 --- /dev/null +++ b/beispiele/personclass1.py @@ -0,0 +1,27 @@ +# personclass1.py + +class Person: + name = "" + age = 0 + gender = None + + +person = Person() + +print(person) +print(person.__class__) +print(person.name) +print(person.age) +print(person.gender) + +person.name = "Joe Doe" +person.age = 32 +person.gender = "m" + +print(person) +print(person.__class__) +print(person.name) +print(person.age) +print(person.gender) + + diff --git a/beispiele/personclass2.py b/beispiele/personclass2.py new file mode 100644 index 0000000..b122999 --- /dev/null +++ b/beispiele/personclass2.py @@ -0,0 +1,27 @@ +# personclass1.py + +class Person: + + def __init__(self, name="", age=0, gender=None): + self.name = name + self.age = age + self.gender = gender + + +person1 = Person() + +print(person1) +print(person1.__class__) +print(person1.name) +print(person1.age) +print(person1.gender) + +person2 = Person("Joe Doe", 32, gender="m") + +print(person2) +print(person2.__class__) +print(person2.name) +print(person2.age) +print(person2.gender) + +