Python KLASSEN: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
Zeile 25: Zeile 25:
 
=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, 19: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