Python KLASSEN: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Die Seite wurde neu angelegt: „ =Links= *https://www.hdm-stuttgart.de/~maucher/Python/html/Klassen.html“
 
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 1: Zeile 1:
=Klasse=
*cat cl.py
<pre>
#!/usr/bin/python
class mycl(object):
def __init__(self,zahl1,zahl2):
  self.z1 = zahl1
  self.z2 = zahl2


def sub(self):
    print self.z1 - self.z2
def add(self):
    print self.z1 + self.z2
</pre>
=Instanz=
*cat inst.py
<pre>
#!/usr/bin/python
from cl import mycl
x = mycl(9,7)
x.sub()
x.add()
</pre>
=Links=
=Links=
*https://www.hdm-stuttgart.de/~maucher/Python/html/Klassen.html
*https://www.hdm-stuttgart.de/~maucher/Python/html/Klassen.html
*https://www.python-kurs.eu/python3_klassen.php

Aktuelle Version vom 4. November 2017, 21:34 Uhr

Klasse

  • cat cl.py
#!/usr/bin/python
class mycl(object):
 def __init__(self,zahl1,zahl2):
   self.z1 = zahl1
   self.z2 = zahl2

 def sub(self):
    print self.z1 - self.z2

 def add(self):
    print self.z1 + self.z2

Instanz

  • cat inst.py
#!/usr/bin/python
from cl import mycl
x = mycl(9,7)
x.sub()
x.add()

Links